diff options
| author | Christoph Berg <myon@debian.org> | 2025-09-15 23:04:33 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2025-09-15 23:04:33 +0200 |
| commit | e1c678ef00f0159bbeb5571e5ebb0d4697121334 (patch) | |
| tree | 6547edef81a62a812a4d0f64e03fda226b5f0a7e /lib | |
| parent | b9daa22c4c3ad51cd4bc0ef624a19f21d01c9305 (diff) | |
| parent | 0a13f1fdb9928b6d012569dd65f7f6ef18fac2f8 (diff) | |
Update upstream source from tag 'upstream/3.0.0_rc1+repack'
Update to upstream version '3.0.0~rc1+repack'
with Debian dir 68c212e23136fecf9ebc6f12ff355579224d27ee
Diffstat (limited to 'lib')
171 files changed, 22864 insertions, 744 deletions
diff --git a/lib/77bit/hash22calc.f90 b/lib/77bit/hash22calc.f90 new file mode 100755 index 00000000..46581a98 --- /dev/null +++ b/lib/77bit/hash22calc.f90 @@ -0,0 +1,42 @@ +program hash22calc
+! Given a valid callsign, calculate and print its 22-bit hash.
+
+ use packjt77
+
+ character*13 callsign
+ character*1 c
+ character*6 basecall
+ logical cok
+
+ nargs=iargc()
+ if(nargs.ne.1) then
+ print*,'Given a valid callsign, print its 22-bit hash.'
+ print*,'Usage: hash22calc <callsign>'
+ print*,' e.g. hash22calc W9ABC'
+ go to 999
+ endif
+ call getarg(1,callsign)
+
+! convert to upper case
+ ilen=len(trim(callsign))
+ do i=1, ilen
+ c=callsign(i:i)
+ if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case
+ callsign(i:i)=c
+ enddo
+
+! check for a valid callsign
+ call chkcall(callsign,basecall,cok)
+ if(.not.cok) then
+ print*,'Invalid callsign'
+ print*,'Usage: hash22calc <callsign>'
+ goto 999
+ endif
+
+! calculate the hash
+ n22 = ihashcall(callsign,22)
+ write(*,'(a,i7.7)') callsign,n22
+
+999 end program hash22calc
+
+include '../chkcall.f90'
diff --git a/lib/77bit/packjt77.f90 b/lib/77bit/packjt77.f90 index af655723..121032a7 100755 --- a/lib/77bit/packjt77.f90 +++ b/lib/77bit/packjt77.f90 @@ -1,5 +1,7 @@ module packjt77
+use packjt77var, only : hash10var,hash12var,hash22var
+
! These variables are accessible from outside via "use packjt77":
parameter (MAXHASH=1000,MAXRECENT=10)
character (len=13), dimension(0:1023) :: calls10=''
@@ -319,8 +321,14 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) call unpack28(n28b,call_2,unpk28_success)
if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false.
call hash10(n10,call_3)
+ if(call_3.eq.'<...>') then
+ ! print*,'pre std n10 ',n10,' call_3 ',call_3
+ call hash10var(n10,call_3,1)
+ ! print*,'std n10 ',n10,' call_3 ',call_3
+ endif
if(nrx.eq.1 .and. &
dxcall13_set .and. &
+ len(trim(dxcall13)).ge.3 .and. &
hashdx10.eq.n10) call_3='<'//trim(dxcall13)//'>'
if(nrx.eq.0 .and. &
mycall13_set .and. &
@@ -370,15 +378,28 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) msg=adjustl(msg)
else if(i3.eq.0 .and. n3.eq.6) then
- read(c77(49:50),'(2b1)') j2a,j2b
- itype=2
- if(j2b.eq.0 .and. j2a.eq.0) itype=1
- if(j2b.eq.0 .and. j2a.eq.1) itype=3
+ read(c77(48:50),'(3b1)') j48,j49,j50
+! bits 48:50
+! itype=1: x00
+! itype=2: xx1
+! itype=3: 010
+ if(j50.eq.1) then
+ itype=2
+ else if(j49.eq.0) then
+ itype=1
+ else if(j48.eq.0) then
+ itype=3
+ else
+ itype=-1
+ unpk77_success=.false.
+ endif
+
if(itype.eq.1) then
! WSPR Type 1
read(c77,2010) n28,igrid4,idbm
2010 format(b28.28,b15.15,b5.5)
idbm=nint(idbm*10.0/3.0)
+ if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false.
call unpack28(n28,call_1,unpk28_success)
if(.not.unpk28_success) unpk77_success=.false.
call to_grid4(igrid4,grid4,unpkg4_success)
@@ -392,6 +413,7 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) read(c77,2020) n28,npfx,idbm
2020 format(b28.28,b16.16,b5.5)
idbm=nint(idbm*10.0/3.0)
+ if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false.
call unpack28(n28,call_1,unpk28_success)
if(.not.unpk28_success) unpk77_success=.false.
write(crpt,'(i3)') idbm
@@ -460,13 +482,17 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) i=index(call_1,' ')
if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.1) call_1(i:i+1)='/R'
if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.2) call_1(i:i+1)='/P'
- if(i.ge.4) call add_call_to_recent_calls(call_1)
+ if(i.ge.4) call add_call_to_recent_calls(call_1)
endif
if(index(call_2,'<').le.0) then
i=index(call_2,' ')
if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.1) call_2(i:i+1)='/R'
if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.2) call_2(i:i+1)='/P'
- if(i.ge.4) call add_call_to_recent_calls(call_2)
+ if(i.ge.4) then
+ call add_call_to_recent_calls(call_2)
+! only hash the "from" call
+ call save_hash_call(call_2,ndum10,ndum12,ndum22)
+ endif
endif
if(igrid4.le.MAXGRID4) then
call to_grid4(igrid4,grid4,unpkg4_success)
@@ -542,10 +568,16 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) n58=n58/38
enddo
call hash12(n12,call_3)
+ if(call_3.eq.'<...>') then
+ ! print*,'pre std n12 1 ',n12,' call_3 ',call_3
+ call hash12var(n12,call_3,1)
+ ! print*,'std n12 1 ',n12,' call_3 ',call_3
+ endif
if(iflip.eq.0) then ! 12 bit hash for TO call
call_1=call_3
call_2=adjustl(c11)//' '
call add_call_to_recent_calls(call_2)
+ call save_hash_call(call_2,ndum10,ndum12,ndum22)
if(nrx.eq.1 .and. &
dxcall13_set .and. mycall13_set .and. &
call_2.eq.dxcall13 .and. &
@@ -582,8 +614,18 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) return
endif
call hash12(n12,call_1)
+ if(call_1.eq.'<...>') then
+ ! print*,'pre std n12 1 ',n12,' call_1 ',call_1
+ call hash12var(n12,call_1,1)
+ ! print*,'std n12 2 ',n12,' call_1 ',call_1
+ endif
if(n12.eq.hashmy12) call_1='<'//trim(mycall13)//'>'
call hash22(n22,call_2)
+ if(call_2.eq.'<...>') then
+ ! print*,'pre std n22 ',n22,' call_2 ',call_2
+ call hash22var(n22,call_2,1)
+ ! print*,'std n22 ',n22,' call_2 ',call_2
+ endif
nrs=52+irpt
write(cexch,1022) nrs,iserial
1022 format(i2,i4.4)
@@ -735,7 +777,7 @@ end subroutine pack28 subroutine unpack28(n28_0,c13,success)
parameter (NTOKENS=2063592,MAX22=4194304)
- logical success
+ logical success,callok
character*13 c13
character*37 c1
character*36 c2
@@ -779,6 +821,11 @@ subroutine unpack28(n28_0,c13,success) ! This is a 22-bit hash of a callsign
n22=n28
call hash22(n22,c13) !Retrieve callsign from hash table
+ if(c13.eq.'<...>') then
+ ! print*,'pre std n22 ',n22,' c13 ',c13
+ call hash22var(n22,c13,1)
+ ! print*,'std n22 ',n22,' c13 ',c13
+ endif
go to 900
endif
@@ -798,11 +845,17 @@ subroutine unpack28(n28_0,c13,success) c4(i5+1:i5+1)//c4(i6+1:i6+1)
c13=adjustl(c13)
+ if(.not.callok(trim(c13))) then
+ c13='QU1RK'
+ success=.false.
+ endif
+
900 i0=index(c13,' ')
if(i0.ne.0 .and. i0.lt.len(trim(c13))) then
c13='QU1RK'
success=.false.
endif
+
return
end subroutine unpack28
@@ -1526,7 +1579,7 @@ subroutine add_call_to_recent_calls(callsign) endif
! Make sure that callsign is hashed
- call save_hash_call(callsign,n10,n12,n22)
+! call save_hash_call(callsign,n10,n12,n22) ! commented out - do this in the calling routine:
return
end subroutine add_call_to_recent_calls
@@ -1624,3 +1677,52 @@ subroutine to_grid(n,grid6,ok) end subroutine to_grid
end module packjt77
+
+logical function callok(w)
+
+ character*(*) w
+ character*1 c1
+ character*2 pfx
+ character*3 sfx
+ logical isdig,islet
+
+ islet(c1)=(ichar(c1).ge.65 .and. ichar(c1).le.90) .or. &
+ (ichar(c1).ge.97 .and. ichar(c1).le.122)
+ isdig(c1)=(ichar(c1).ge.48 .and. ichar(c1).le.57)
+
+ callok=.false.
+ n=len(trim(w))
+ if(n.lt.3) return !Must be at lkeast three characters
+ if(w(1:1).eq.'Q') return !Callsigns can't start with Q
+
+ i0=0
+ do i=n,1,-1
+ if(isdig(w(i:i))) exit
+ enddo
+ i0=i !Call area position in word
+
+ if(i0.ne.2 .and. i0.ne.3) return
+
+ pfx=w(1:i0-1) !Prefix, without call area
+ sfx=w(i0+1:) !Suffix
+
+ nlp=0
+ ndp=0
+ np=len(trim(pfx))
+ do i=1,np
+ if(isdig(pfx(i:i))) ndp=ndp+1
+ if(islet(pfx(i:i))) nlp=nlp+1
+ enddo
+ if(nlp.eq.0) return !Prefix must have at least one letter
+
+ nls=0
+ ns=len(trim(sfx))
+ do i=1,ns
+ if(islet(sfx(i:i))) nls=nls+1
+ enddo
+ if(nls.lt.ns) return !Suffix must be all letters
+
+ callok=.true.
+
+ return
+end function callok
diff --git a/lib/EchoCallSim.f90 b/lib/EchoCallSim.f90 new file mode 100755 index 00000000..eb3b7276 --- /dev/null +++ b/lib/EchoCallSim.f90 @@ -0,0 +1,115 @@ +program EchoCallSim
+
+! Generate simulated transmissions for echo_call mode.
+
+ use wavhdr
+ parameter (NSPS=4096,NZ=3*12000)
+ parameter (NMAX=6*NSPS) !Samples in .wav file, 2.2*12000
+ type(hdr) h !Header for .wav file
+ integer*2 iwave(NZ) !Generated waveform
+ integer itone(6) !Channel symbols, values 0-37
+ real*4 xnoise(NMAX) !Generated random noise
+ real*4 dat(NMAX) !Generated real data
+ complex cdat(NMAX) !Generated complex waveform
+ complex z
+ real*8 f0,dt,twopi,phi,dphi,fsample,freq
+ character callsign*6,fname*17,arg*8
+
+! character*37 c
+! data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+
+ nargs=iargc()
+ if(nargs.ne.7) then
+ print*,'Usage: EchoCallSim callsign f0 fdop fspread ndf nfiles snrdb'
+ print*,'Example: EchoCallSim K1JT 1500 0.0 10.0 10 10 -15'
+ go to 999
+ endif
+ call getarg(1,callsign)
+ call getarg(2,arg)
+ read(arg,*) f0
+ call getarg(3,arg)
+ read(arg,*) fdop
+ call getarg(4,arg)
+ read(arg,*) fspread
+ call getarg(5,arg)
+ read(arg,*) ndf
+ call getarg(6,arg)
+ read(arg,*) nfiles
+ call getarg(7,arg)
+ read(arg,*) snrdb
+
+ write(*,1000)
+1000 format(' N f0 fDop fSpread ndf SNR File name'/63('-'))
+
+ call gen_echocall(callsign,itone)
+
+ twopi=8.d0*atan(1.d0)
+ rms=100.
+ fsample=12000.d0 !Sample rate (Hz)
+ npts=NMAX !Total samples in .wav file
+ nfft=npts
+ nh=nfft/2
+ dt=1.d0/fsample !Sample interval (s)
+ df=12000.0/NSPS
+
+ do ifile=1,nfiles !Loop over requested number of files
+ xnoise=0.
+ if(snrdb.lt.90) then
+ do i=1,npts
+ xnoise(i)=gran() !Generate gaussian noise
+ enddo
+ endif
+
+ bandwidth_ratio=2500.0/6000.0
+ sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb)
+ if(snrdb.gt.90.0) sig=1.0
+
+ phi=0.d0
+ dphi=0.d0
+ k=0
+ do j=1,6
+ freq=f0 + fdop + itone(j)*ndf
+ dphi=twopi*freq*dt
+ do i=1,NSPS
+ phi=phi + dphi
+ if(phi.gt.twopi) phi=phi-twopi
+ xphi=phi
+ z=cmplx(cos(xphi),sin(xphi))
+ k=k+1
+ cdat(k)=sig*z
+ enddo
+ enddo
+
+ if(fspread.gt.0.0) call fspread_lorentz(cdat,fspread)
+
+ dat=aimag(cdat) + xnoise !Add generated AWGN noise
+ fac=32767.0
+ if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts))
+ if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts))
+ iwave(npts+1:)=0
+
+ nDop=nint(fdop)
+ nDopAudio=0
+ nfrit=0
+ f1=f0 + fdop
+ call save_echo_params(nDop,nDopAudio,nfrit,f1,fspread,ndf,itone,iwave,1)
+
+ h=default_header(12000,NZ)
+ n=6*(ifile-1)
+ ihr=n/3600
+ imin=(n-3600*ihr)/60
+ isec=mod(n,60)
+ write(fname,1102) ihr,imin,isec
+1102 format('000000_',3i2.2,'.wav')
+ open(10,file=trim(fname),access='stream',status='unknown')
+ write(10) h,iwave !Save the .wav file
+ close(10)
+
+ write(*,1110) ifile,f0,fdop,fspread,ndf,snrdb,fname
+1110 format(i4,3f7.1,i5,f7.1,2x,a17)
+
+ enddo
+
+999 end program EchoCallSim
+
+
diff --git a/lib/ana64.f90 b/lib/ana64.f90 index f7586756..13637730 100755 --- a/lib/ana64.f90 +++ b/lib/ana64.f90 @@ -1,7 +1,5 @@ subroutine ana64(iwave,npts,c0)
- use timer_module, only: timer
-
integer*2 iwave(npts) !Raw data at 12000 Hz
complex c0(0:npts-1) !Complex data at 6000 Hz
save
diff --git a/lib/astrosub.f90 b/lib/astrosub.f90 index f6f618fc..947f1442 100755 --- a/lib/astrosub.f90 +++ b/lib/astrosub.f90 @@ -11,7 +11,7 @@ contains subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid_cp, &
hisgrid_cp,AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8, &
- ntsky,ndop,ndop00,RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1, &
+ ntsky,ndop,ndop00,RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,extraazel,techo8,width1, &
width2,bTx,AzElFileName_cp,jpleph_file_name_cp) &
bind (C, name="astrosub")
@@ -19,6 +19,7 @@ contains use :: C_interface_module, only: C_int, C_double, C_bool, C_ptr, C_string_value, assignment(=)
integer(C_int), intent(in), value :: nyear, month, nday
+ logical(C_int), value :: extraazel
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, &
@@ -75,11 +76,12 @@ contains 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
- if (azel_extra_lines.ge.1) write(15, 1020, err=10) poloffset8, &
+ if (extraazel .or. (azel_extra_lines.ge.1)) write(15, 1020, err=10) poloffset8, &
xnr8,Dgrd8,width1,width2
1010 format( &
i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ &
diff --git a/lib/avecho.f90 b/lib/avecho.f90 index 7b499a05..51828d7b 100755 --- a/lib/avecho.f90 +++ b/lib/avecho.f90 @@ -1,31 +1,51 @@ -subroutine avecho(id2,ndop,nfrit,nauto,navg,nqual,f1,xlevel,snrdb, &
- db_err,dfreq,width,bDiskData)
+subroutine avecho(id2_0,ndop,nfrit,nauto,ndf,navg,nqual,f1,xlevel, &
+ snrdb,db_err,dfreq,width,bDiskData,bEchoCall,txcall,rxcall,xdt)
- integer TXLENGTH
- parameter (TXLENGTH=27648) !27*1024
+ parameter (NTX=6*4096)
parameter (NFFT=32768,NH=NFFT/2)
parameter (NZ=4096)
- integer*2 id2(34560) !Buffer for Rx data
+ integer*2 id2_0(NTX+4096) !Raw Rx data
+ integer*2 id2(NTX+4096) !Local copy of Rx data
+ integer*2 id2_best(NTX+4096) !Best time-shifted Rx data
+ integer*2 id2a(15) !Just the parameter portion
+ integer*4 itone4(6)
+ integer*1 itone1(6)
real sa(NZ) !Avg spectrum relative to initial Doppler echo freq
real sb(NZ) !Avg spectrum with Dither and changing Doppler removed
- real, dimension (:,:), allocatable :: sax
- real, dimension (:,:), allocatable :: sbx
+ real, dimension (:,:), allocatable :: sax !2D sa spectrum with navg slots
+ real, dimension (:,:), allocatable :: sbx !2D sb spectrum with navg slots
integer nsum !Number of integrations
real dop0 !Doppler shift for initial integration (Hz)
real dop !Doppler shift for current integration (Hz)
real s(8192)
real x(NFFT)
integer ipkv(1)
- logical ex
- logical*1 bDiskData
+ logical*1 bDiskData,bEchoCall
+ logical searching
complex c(0:NH)
+ character*6 txcall,rxcall
+ equivalence (itone1,id2a(13))
equivalence (x,c),(ipk,ipkv)
common/echocom/nclearave,nsum,blue(NZ),red(NZ)
common/echocom2/fspread_self,fspread_dx
data navg0/-1/
save dop0,navg0,sax,sbx
+ if(bEchoCall .and. .not.bDiskData) then
+! Calculate the transmitted tones for real-time Echo Call testing
+ call gen_echocall(txcall,itone4)
+ itone1=itone4
+ id2_0(13:15)=id2a(13:15) !Copy the tone values into id2_0
+ endif
+
+ fspread=fspread_dx !Use the predicted spread
+ if(bDiskData) fspread=width
+ if(nauto.eq.1) fspread=fspread_self
+ fspread=min(max(0.04,fspread),700.0)
+ width=fspread
+
if(navg.ne.navg0) then
+! If navg changes, start fresh by reallocating sax and sbx
if(allocated(sax)) deallocate(sax)
if(allocated(sbx)) deallocate(sbx)
allocate(sax(1:navg,1:NZ))
@@ -34,64 +54,113 @@ subroutine avecho(id2,ndop,nfrit,nauto,navg,nqual,f1,xlevel,snrdb, & navg0=navg
endif
- fspread=fspread_dx !### Use the predicted Doppler spread ###
- if(bDiskData) fspread=width
- if(nauto.eq.1) fspread=fspread_self
- inquire(file='fspread.txt',exist=ex)
- if(ex) then
- open(39,file='fspread.txt',status='old')
- read(39,*) fspread
- close(39)
- endif
- fspread=min(max(0.04,fspread),700.0)
- width=fspread
- dop=ndop
- sq=0.
- do i=1,TXLENGTH
- x(i)=id2(i)
- sq=sq + x(i)*x(i)
- enddo
- xlevel=10.0*log10(sq/TXLENGTH)
+ sq=sum(float(id2_0(16:NTX))**2)
+ xlevel=10.0*log10(sq/(NTX-15))
+ if(navg.eq.1) nclearave=1
if(nclearave.ne.0) nsum=0
+ dop=ndop
if(nsum.eq.0) then
dop0=dop !Remember the initial Doppler
sax=0. !Clear the average arrays
sbx=0.
endif
- x(TXLENGTH+1:)=0.
- x=x/TXLENGTH
- call four2a(x,NFFT,1,-1,0)
df=12000.0/NFFT
- do i=1,8192 !Get spectrum 0 - 3 kHz
- s(i)=real(c(i))**2 + aimag(c(i))**2
- enddo
-
fnominal=1500.0 !Nominal audio frequency w/o doppler or dither
ia=nint((fnominal+dop0-nfrit)/df)
ib=nint((f1+dop-nfrit)/df)
- if(ia.lt.2048 .or. ib.lt.2048 .or. ia.gt.6144 .or. ib.gt.6144) then
- snrdb=0.
- db_err=0.
- dfreq=0.
- go to 900
+ snrdb=0.
+ db_err=0.
+ dfreq=0.
+
+! If some parameter is way off, abort this procedure
+ if(ia.lt.2048 .or. ib.lt.2048 .or. ia.gt.6144 .or. ib.gt.6144) go to 900
+
+ dtime=0.05 !Setup for searching a range of DT
+ idtbest=0
+ snrbest=-9999.
+ idt1=-10
+ idt2=10
+
+10 searching=(idt1.ne.idt2)
+ do idt=idt1,idt2
+
+! Copy time-shifted data from id2_0 to id2
+ i0=12000*dtime*idt
+ id2(1:15)=id2_0(1:15)
+ do i=16,NTX
+ j=i+i0
+ id2(i)=0
+ if(j.ge.16 .and. j.le.NTX) id2(i)=id2_0(j)
+ enddo
+
+! Shift all tone frequencies to 1500 Hz. Return modified data in id2 and decoded
+! message in rxcall.
+ rxcall=' '
+ call decode_echo(id2,searching,rxcall)
+
+ x(1:NTX)=id2(1:NTX)
+ x(NTX+1:)=0.
+ x=x/NTX
+ call four2a(x,NFFT,1,-1,0) !Compute the tone-aligned spectrum
+ do i=1,8192 !Array s(1:8192) is spectrum 0-3 kHz
+ s(i)=real(c(i))**2 + aimag(c(i))**2
+ enddo
+
+ if(searching) then
+ do i=1,NZ
+ sa(i)=s(ia+i-2048) !Center at initial doppler freq
+ sb(i)=s(ib+i-2048) !Center at expected echo freq
+ enddo
+ else
+ nsum=nsum+1
+ endif
+
+ call echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,dfreq,snr_detect)
+
+! nqual=snr_detect-2
+! if(nqual.lt.0) nqual=0
+! if(nqual.gt.10) nqual=10
+ if(searching) then
+ if(snrdb.gt.snrbest .and. (ndf.eq.0 .or. dfreq.le.0.5*ndf)) then
+ snrbest=snrdb
+ idtbest=idt
+ j=mod(nsum,navg)+1
+
+ do i=1,NZ
+ sax(j,i)=s(ia+i-2048) !Center at initial doppler freq
+ sbx(j,i)=s(ib+i-2048) !Center at expected echo freq
+ enddo
+
+! Copy time-shifted data from id2_0 to id2_best
+ i0=12000*dtime*idt
+ id2_best(1:15)=id2_0(1:15)
+ do i=16,NTX
+ j=i+i0
+ id2_best(i)=0
+ if(j.ge.16 .and. j.le.NTX) id2_best(i)=id2_0(j)
+ enddo
+
+ endif
+ endif
+ enddo
+ if(searching) then
+ idt1=idtbest
+ idt2=idtbest
+ go to 10
endif
- nsum=nsum+1
- j=mod(nsum-1,navg)+1
+ xdt=idtbest*dtime
do i=1,NZ
- sax(j,i)=s(ia+i-2048) !Center at initial doppler freq
- sbx(j,i)=s(ib+i-2048) !Center at expected echo freq
sa(i)=sum(sax(1:navg,i))
sb(i)=sum(sbx(1:navg,i))
enddo
-
call echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,dfreq,snr_detect)
nqual=snr_detect-2
if(nqual.lt.0) nqual=0
if(nqual.gt.10) nqual=10
-
+
! Scale for plotting
redmax=maxval(red)
fac=10.0/max(redmax,10.0)
@@ -116,5 +185,7 @@ subroutine avecho(id2,ndop,nfrit,nauto,navg,nqual,f1,xlevel,snrdb, & blue=blue-0.5*(bblue1+bblue2)
900 call sleep_msec(10) !Avoid the "blue Decode button" syndrome
+ if(abs(dfreq).ge.1000.0) dfreq=0.
+
return
end subroutine avecho
diff --git a/lib/cablog.f90 b/lib/cablog.f90 new file mode 100755 index 00000000..08fecbad --- /dev/null +++ b/lib/cablog.f90 @@ -0,0 +1,142 @@ +program cablog
+
+ character*100 line,infile,outfile
+ character cband*4,cmode*2,cdate*10,cutc*4,callsign*10,mycall*10
+ character csent*4,crcvd*4,dsent*4,drcvd*4,g1*4
+ character*3 cmo(12)
+ integer icomma(20)
+ logical map65
+ logical isgrid,gridx
+ data cmo/'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep', &
+ 'Oct','Nov','Dec'/
+
+ isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. &
+ g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. &
+ g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73'
+
+ nargs=iargc()
+ if(nargs.ne.4) then
+ print*,"Program cablog converts file 'wsjtx.log' written by WSJT-X"
+ print*,"(or wsjt.log written by MAP65) to a bare-bones Cabrillo"
+ print*,"log for the ARRL International EME Contest. You will"
+ print*,"certainly need to edit the header information, and you may"
+ print*,"edit the log elsewhere as required."
+ print*,' '
+ print*,'Usage: cablog <MyCall> <sent> <rcvd> <infile>'
+ print*,'Examples: cablog W2ZQ -15 -16 wsjtx.log'
+ print*,' cablog W2ZQ O O wsjt.log'
+ go to 999
+ endif
+ call getarg(1,mycall)
+ outfile=trim(mycall)//'.log'
+ call getarg(2,dsent)
+ gridx=isgrid(dsent)
+ call getarg(3,drcvd)
+ call getarg(4,infile)
+ open(10,file=trim(infile),status='old')
+ open(12,file=trim(outfile),status='unknown')
+
+ write(12,1000)
+1000 format('START-OF-LOG: 3.0'/ &
+ 'CONTEST: ARRL-EME'/ &
+ 'CALLSIGN: '/ &
+ 'CATEGORY-OPERATOR: '/ &
+ 'CATEGORY-BAND: '/ &
+ 'CATEGORY-MODE: '/ &
+ 'EMAIL: '/ &
+ 'OPERATORS: '/ &
+ 'CATEGORY-POWER: HIGH'/ &
+ 'CATEGORY-TRANSMITTER: ONE'/ &
+ 'CATEGORY-STATION: FIXED'/ &
+ 'CATEGORY-TIME: 24-HOURS'/ &
+ 'CATEGORY-ASSISTED: ASSISTED'/ &
+ 'LOCATION: SNJ'/ &
+ 'CLAIMED-SCORE: '/ &
+ 'CLUB: '/ &
+ 'NAME: '/ &
+ 'ADDRESS: '/ &
+ 'ADDRESS: '/ &
+ 'ADDRESS: '/ &
+ 'CREATED-BY: cablog (C) K1JT')
+
+ n=0
+ map65=.false.
+
+ do nn=1,9999
+ read(10,'(a100)',end=900) line
+ if(len(trim(line)).eq.0) cycle
+ if(line(6:6).ge.'A' .and. line(6:6).le.'Z') map65=.true.
+ n=n+1
+ k=0
+ do j=1,100
+ if(line(j:j).eq.',') then
+ k=k+1
+ icomma(k)=j
+ endif
+ enddo
+ cmode='DG'
+ if(index(line,',CW,').gt.10) cmode='CW'
+
+ if(map65) then
+ do i=1,12
+ if(cmo(i).eq.line(6:8)) write(cdate(6:7),'(i2.2)') i
+ enddo
+ cdate(1:5)=line(1:5)
+ cdate(8:10)=line(9:11)
+ cutc=line(13:14)//line(16:17)
+ i0=index(line(19:),',')
+ callsign=line(19:17+i0)
+ cband='144 '
+ csent=dsent
+ crcvd=drcvd
+ else
+ cdate=line(1:10)
+ cutc=line(32:33)//line(35:36)
+ i0=index(line(41:),',')
+ callsign=line(41:39+i0)
+ read(line(icomma(6)+1:icomma(7)-1),*,err=10,end=10) freq
+ go to 20
+10 print*,'***Error at line ',n
+ print*,trim(line)
+20 if(freq.ge.50.0 .and. freq.le.54.0) cband='50 '
+ if(freq.ge.144.0 .and. freq.le.148.0) cband='144 '
+ if(freq.ge.28.0 .and. freq.le.29.0) cband='144 '
+ if(freq.ge.222.0 .and. freq.le.225.0) cband='222 '
+ if(freq.ge.420.0 .and. freq.le.450.0) cband='432 '
+ if(freq.ge.902.0 .and. freq.le.928.0) cband='902 '
+ if(freq.ge.1240.0 .and. freq.le.1300.0) cband='1.2G'
+ if(freq.ge.2300.0 .and. freq.le.2450.0) cband='2.3G'
+ if(freq.ge.3300.0 .and. freq.le.3500.0) cband='3.4G'
+ if(freq.ge.5650.0 .and. freq.le.5925.0) cband='5.7G'
+ if(freq.ge.10000.0 .and. freq.le.10500.0) cband='10G '
+ if(freq.ge.24000.0 .and. freq.le.24250.0) cband='24G '
+ if(icomma(8).eq.icomma(9)-1) then
+ csent=dsent
+ else
+ csent=line(icomma(8)+1:icomma(9)-1)
+ endif
+ if(icomma(9).eq.icomma(10)-1) then
+ crcvd=drcvd
+ else
+ crcvd=line(icomma(9)+1:icomma(10)-1)
+ endif
+ endif
+ if(gridx) then
+ csent=dsent
+ crcvd=line(icomma(5)+1:icomma(6)-1)
+ endif
+
+ write(12,1030) cband,cmode,cdate,cutc,mycall,csent,callsign,crcvd
+1030 format('QSO: ',a4,1x,a2,1x,a10,1x,a4,1x,a6,1x,a4,4x,a10,1x,a4)
+ enddo
+
+900 write(12,1900)
+1900 format('END-OF-LOG:')
+ write(*,1910) n,trim(outfile)
+1910 format('Processed',i5,' QSOs.'/'Output file: ',a)
+
+999 end program cablog
+
+!2023-10-28,00:17:00,2023-10-28,00:21:00,G7TZZ,IO92,1296.083100,Q65,-17,-17,,,,
+!2023-Nov-30,20:31,W8WN,EM77,0,Q65A
+
diff --git a/lib/chkfft.f90 b/lib/chkfft.f90 index e9448171..c038c4e7 100755 --- a/lib/chkfft.f90 +++ b/lib/chkfft.f90 @@ -143,11 +143,11 @@ program chkfft if(n2.eq.1 .or. n2.eq.999999) then
write(*,1050) nfft,time,rms,freq,mflops,iter,tplan
write(12,1050) nfft,time,rms,freq,mflops,iter,tplan
-1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1)
+1050 format(i8,f11.7,f12.8,f7.1,f8.1,i8,f6.1)
else
write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan
write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan
-1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1)
+1060 format(i2,i8,f11.7,f12.8,f7.1,f8.1,i8,f6.1)
endif
if(mod(ii,50).eq.0) call four2a(0,-1,0,0,0)
enddo
diff --git a/lib/chkfft3.f90 b/lib/chkfft3.f90 index 7b6d74e1..6560e48f 100755 --- a/lib/chkfft3.f90 +++ b/lib/chkfft3.f90 @@ -1,25 +1,24 @@ program chkfft
! Tests and times one-dimensional FFTs computed by FFTW3
+
use, intrinsic :: iso_c_binding
use FFTW3
parameter (NMAX=8*1024*1024) !Maximum FFT length
complex a(NMAX),b(NMAX),c(NMAX)
real ar(NMAX),br(NMAX),cr(NMAX)
real mflops
-! integer*8 plan1,plan2 !Pointers to stored plans
type(C_PTR) :: plan1,plan2 !Pointers to FFTW plans
character infile*12,arg*8
logical list
common/patience/npatience
equivalence (a,ar),(b,br),(c,cr)
-! include 'fftw3.f90' !FFTW definitions
nargs=iargc()
if(nargs.ne.5) then
print*,'Usage: chkfft3 <nfft | infile> nr nw nc np'
print*,' nfft: length of FFT'
- print*,' nfft=0: do lengths 2^n, n=2^4 to 2^23'
+ print*,' nfft=0: do lengths 2^n, n=2^8 to 2^23'
print*,' infile: name of file with nfft values, one per line'
print*,' nr: 0/1 to not read (or read) wisdom'
print*,' nw: 0/1 to not write (or write) wisdom'
@@ -86,7 +85,7 @@ program chkfft 1020 format(' NFFT Time rms MHz MFlops iters', &
' tplan'/61('-'))
else
- n1=4
+ n1=8
n2=23
write(*,1030)
1030 format(' n N=2^n Time rms MHz MFlops iters', &
@@ -156,11 +155,11 @@ program chkfft if(n2.eq.1 .or. n2.eq.999999) then
write(*,1050) nfft,time,rms,freq,mflops,iter,tplan
write(12,1050) nfft,time,rms,freq,mflops,iter,tplan
-1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1)
+1050 format(i8,f11.7,f12.8,f7.0,f8.0,i8,f6.1)
else
write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan
write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan
-1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1)
+1060 format(i2,i8,f11.7,f12.8,f7.0,f8.0,i8,f6.1)
endif
enddo
diff --git a/lib/cwsim.f90 b/lib/cwsim.f90 new file mode 100755 index 00000000..e9034a9f --- /dev/null +++ b/lib/cwsim.f90 @@ -0,0 +1,235 @@ +program cwsim
+
+! Generate simulated audio for a CW message sent repeatedly for 60 seconds
+
+ use wavhdr
+ parameter (NMAX=60*12000)
+ type(hdr) h !Header for the .wav file
+ integer*2 iwave(NMAX) !Generated waveform (no noise)
+ integer icw(500) !Encoded CW message bits
+ complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading
+ complex cdat(0:NMAX-1) !Complex waveform
+ real dat(NMAX) !Audio waveform
+ real*4 xnoise(NMAX) !Generated random noise
+ character*60 message
+ character*12 arg
+
+ nargs=iargc()
+ if(nargs.ne.6) then
+ print*,'Usage: cwsim "message" freq bw wpm fspread snr'
+ print*,'Example: cwsim "CQ CQ CQ DE K1JT K1JT K1JT" 700 100 20 100 -10'
+ go to 999
+ endif
+
+ call getarg(1,message)
+ call getarg(2,arg)
+ read(arg,*) ifreq !Audio frequency (Hz)
+ call getarg(3,arg)
+ read(arg,*) bw !Bandwidth (Hz)
+ call getarg(4,arg)
+ read(arg,*) wpm !CW speed, words per minute
+ call getarg(5,arg)
+ read(arg,*) fspread !Doppler spread in Hz
+ call getarg(6,arg)
+ read(arg,*) snrdb !S/N in dB (2500 hz reference BW)
+
+ rms=500.0
+ bandwidth_ratio=2500.0/6000.0
+ sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb)
+ twopi=8.0*atan(1.0)
+
+ h=default_header(12000,NMAX)
+ open(10,file='000000_0000.wav',access='stream',status='unknown')
+ do i=1,NMAX !Generate gaussian noise
+ xnoise(i)=gran()
+ enddo
+
+ itone=0
+ call morse(message,icw,ncw)
+ call cwsig(icw,ncw,ifreq,wpm,sig,cdat)
+ nfft=NMAX
+
+ if(fspread.ne.0) then !Apply specified Doppler spread
+ nh=nfft/2
+ df=12000.0/nfft
+ cspread(0)=1.0
+ cspread(nh)=0.
+ b=6.0 !Use truncated Lorenzian shape for fspread
+ do i=1,nh
+ f=i*df
+ x=b*f/fspread
+ z=0.
+ a=0.
+ if(x.lt.3.0) then !Cutoff beyond x=3
+ a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian amplitude
+ phi1=twopi*rran() !Random phase
+ z=a*cmplx(cos(phi1),sin(phi1))
+ endif
+ cspread(i)=z
+ z=0.
+ if(x.lt.3.0) then !Same thing for negative freqs
+ phi2=twopi*rran()
+ z=a*cmplx(cos(phi2),sin(phi2))
+ endif
+ cspread(nfft-i)=z
+ enddo
+
+ call four2a(cspread,nfft,1,1,1) !Transform to time domain
+ sum=0.
+ do i=0,nfft-1
+ p=real(cspread(i))**2 + aimag(cspread(i))**2
+ sum=sum+p
+ enddo
+ avep=sum/nfft
+ fac=sqrt(1.0/avep)
+ cspread=fac*cspread !Normalize to constant avg power
+ cdat=cspread*cdat !Apply Rayleigh fading
+ endif
+
+ dat=aimag(cdat) + xnoise
+
+ cdat=dat
+ call four2a(cdat,nfft,1,-1,1) !c2c to frequency domain
+ ia=max(250/df,(ifreq-0.5*bw)/df)
+ ib=ia+bw/df
+ cdat(0:ia)=0.
+ cdat(ib:)=0.
+ call four2a(cdat,nfft,1,+1,1) !c2c to time domain
+ fac=sqrt(5000/bw)/nfft
+ dat=fac*real(cdat)
+
+ iwave=nint(rms*dat)
+ write(10) h,iwave
+ close(10)
+
+999 end program cwsim
+
+subroutine cwsig(icw,ncw,ifreq,wpm,sig,cdat)
+
+ parameter(NMAX=60*12000)
+ integer icw(ncw)
+ complex cdat(NMAX)
+ complex z(NMAX)
+ real x(NMAX)
+ real y(NMAX)
+ real*8 dt,twopi,phi,dphi,fsample,tdit,t
+
+ nspd=nint(1.2*12000.0/wpm)
+ fsample=12000.d0 !Sample rate (Hz)
+ dt=1.d0/fsample !Sample interval (s)
+ tdit=nspd*dt
+ twopi=8.d0*atan(1.d0)
+ dphi=twopi*ifreq*dt
+ phi=0.
+ k=12000 !Start audio at t = 1.0 s
+ t=0.
+ npts=59*12000
+ x=0.
+ do i=1,npts
+ t=t+dt
+ j=nint(t/tdit) + 1
+ j=mod(j-1,ncw) + 1
+ phi=phi + dphi
+ if(phi.gt.twopi) phi=phi-twopi
+ xphi=phi
+ k=k+1
+ x(k)=icw(j)
+ z(k)=cmplx(cos(xphi),sin(xphi))
+ if(t.ge.59.5) exit
+ enddo
+
+ nadd=0.004/dt
+ call smo(x,npts,y,nadd)
+ y=y/nadd
+ cdat=sig*y*z
+
+ return
+end subroutine cwsig
+
+subroutine morse(msg,idat,n)
+
+! Convert ascii message to a Morse code bit string.
+! Dash = 3 dots
+! Space between dots, dashes = 1 dot
+! Space between letters = 3 dots
+! Space between words = 7 dots
+
+ character*(*) msg
+ integer idat(500)
+ integer*1 ic(21,38)
+ data ic/ &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, &
+ 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, &
+ 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, &
+ 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, &
+ 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, &
+ 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, &
+ 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, &
+ 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, &
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space
+ save
+
+ msglen=len(trim(msg))
+ idat=0
+ n=6
+ do k=1,msglen
+ jj=ichar(msg(k:k))
+ if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case
+ if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers
+ if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters
+ if(jj.eq.47) j=36 !Slash (/)
+ if(jj.eq.32) j=37 !Word space
+ j=j+1
+
+! Insert this character
+ nmax=ic(21,j)
+ if (n + nmax + 4 .gt. size (idat)) exit
+ do i=1,nmax
+ n=n+1
+ idat(n)=ic(i,j)
+ enddo
+
+! Insert character space of 2 dit lengths:
+ n=n+1
+ idat(n)=0
+ n=n+1
+ idat(n)=0
+ enddo
+
+! Insert word space at end of message
+ do j=1,4
+ n=n+1
+ idat(n)=0
+ enddo
+
+ return
+end subroutine morse
diff --git a/lib/decode_echo.f90 b/lib/decode_echo.f90 new file mode 100755 index 00000000..dce45fe4 --- /dev/null +++ b/lib/decode_echo.f90 @@ -0,0 +1,78 @@ +subroutine decode_echo(id2,searching,rxcall)
+
+! For EchoCall mode, recovers transmitted callsign from received echoes.
+! id2(NZ) received echo data
+! rxcall decoded message (callsign, usually)
+! Time alignment of received data is assumed accurate, as EME delay is known.
+
+ parameter (NSPS=4096,NZ=6*NSPS)
+ integer*2 id2(NZ) !Raw Rx data
+ integer itone(6) !Tone offsets corresponding to ransmitted callsign
+ integer ipk(1)
+ logical searching
+ complex c0(0:NZ) !Analytic data, 12000 Hz sample rate
+ complex c1(0:NSPS-1) !Data for a single echo character
+ complex c2(0:NZ) !Analytic data with shifted tone freqs
+ character*6 rxcall !The recovered callsign
+ real s(0:NSPS-1) !Spectrum for one received character
+ real p(0:NSPS-1,6) !Summed spectra for all six received characters
+ real a(3)
+ character*37 c
+ common/echocom/nclearave,nsum,blue(4096),red(4096)
+ equivalence (ipk1,ipk(1))
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+
+! Retrieve params known at time of transmission and saved in id2
+ call save_echo_params(nDop,nDopAudio,nfrit,f1,fspread,ndf,itone,id2,-1)
+
+ df=12000.0/NSPS
+ if(ndf.lt.10 .or. ndf.gt.30) return
+ if(f1.eq.0.0) f1=1500.0
+ i1=nint((f1 - 5*ndf)/df)
+ i2=nint((f1 + 42*ndf)/df)
+ if(i1.le.0 .or. i1.gt.4096 .or. i2.le.0 .or. i2.gt.4096) return
+ nn=i2-i1+1
+
+ if(nclearave.ne.0) p=0.
+ nfft=NZ
+ df1=12000.0/nfft
+ fac=2.0/(32767.0*nfft)
+ c0(0:NZ-1)=fac*id2(1:NZ)
+ c0(0:14)=0.
+ call four2a(c0,nfft,1,-1,1) !Forward c2c FFT
+ c0(nfft/2+1:nfft-1)=0.
+ c0(0)=0.5*c0(0)
+ call four2a(c0,nfft,1,1,1) !Inverse c2c FFT; c0 is analytic sig
+
+ rxcall=' '
+ nskip=2*fspread/df
+
+ do j=1,6
+ ia=(j-1)*NSPS
+ ib=ia+NSPS-1
+ c1=c0(ia:ib)
+ call four2a(c1,NSPS,1,-1,1) !Forward c2c
+ do i=0,NSPS/2
+ s(i)=real(c1(i))**2 + aimag(c1(i))**2
+ enddo
+ if(.not.searching) then
+ p(:,j)=p(:,j) + s !Sum the spectra for each character
+ ipk=maxloc(p(i1:i2,j))
+ k=nint(((ipk1+i1-1)*df - f1)/ndf) + 1
+ if(k.ge.1 .and. k.le.37) rxcall(j:j)=c(k:k) !SNR test here ???
+ endif
+ enddo
+
+ do j=1,6 !Move all tone frequencies to f1
+ ia=(j-1)*NSPS
+ ib=ia+NSPS-1
+ a=0.
+ a(1)=-itone(j)*ndf
+ call twkfreq(c0(ia:ib),c2(ia:ib),NSPS,12000.0,a)
+ enddo
+
+! Return real(c2) as id2 ...
+ id2(16:NZ)=32767.0*real(c2(15:NZ-1))
+
+ return
+end subroutine decode_echo
diff --git a/lib/decode_msk144.f90 b/lib/decode_msk144.f90 new file mode 100755 index 00000000..4c8bd920 --- /dev/null +++ b/lib/decode_msk144.f90 @@ -0,0 +1,57 @@ +subroutine decode_msk144(audio_samples, params, data_dir)
+ include 'jt9com.f90'
+
+ ! constants
+ integer, parameter :: SAMPLING_RATE = 12000
+ integer, parameter :: BLOCK_SIZE = 7168
+ integer, parameter :: STEP_SIZE = BLOCK_SIZE / 2
+ integer, parameter :: CALL_LENGTH = 12
+
+ ! aguments
+ integer*2 audio_samples(NMAX)
+ type(params_block) :: params
+ character(len = 500) :: data_dir
+
+ ! parameters of mskrtd
+ integer*2 :: buffer(BLOCK_SIZE)
+ real :: tsec
+ logical :: bshmsg = .false. ! enables shorthand messages
+ logical :: btrain = .false. ! turns on training in MSK144 mode
+ real*8 :: pcoeffs(5) = (/ 0.0, 0.0, 0.0, 0.0, 0.0 /); ! phase equalization
+ logical :: bswl = .false.
+ character(len = 80) :: line
+ character(len = CALL_LENGTH) :: mycall
+ character(len = CALL_LENGTH) :: hiscall
+
+ ! local variables
+ integer :: sample_count
+ integer :: position
+ integer :: message_count = 0
+
+
+ ! decode in 0.3s blocks
+ sample_count = params%ntr * SAMPLING_RATE
+ mycall = transfer(params%mycall, mycall) ! string to char[]
+ hiscall = transfer(params%hiscall, hiscall)
+
+ do position = 1, sample_count - BLOCK_SIZE + 1, STEP_SIZE
+ buffer = audio_samples(position : position + BLOCK_SIZE - 1)
+ tsec = position / REAL(SAMPLING_RATE)
+
+ call mskrtd(buffer, params%nutc, tsec, params%ntol, params%nfqso, params%ndepth, &
+ mycall, hiscall, bshmsg, btrain, pcoeffs, bswl, data_dir, line)
+
+ if (line(1:1) .ne. char(0)) then
+ line = line(1:index(line, char(0))-1)
+ write(*, 1001) line
+ 1001 format(a80)
+ message_count = message_count + 1;
+ end if
+ end do
+
+ if (.not. params%ndiskdat) then
+ write(*, 1002) 0, message_count, 0
+ 1002 format('<DecodeFinished>', 2i4, i9)
+ end if
+
+end subroutine decode_msk144
\ No newline at end of file diff --git a/lib/decoder.f90 b/lib/decoder.f90 index baf3ddbf..a5fc4509 100755 --- a/lib/decoder.f90 +++ b/lib/decoder.f90 @@ -7,10 +7,21 @@ subroutine multimode_decoder(ss,id2,params,nfsample) use jt65_decode
use jt9_decode
use ft8_decode
+ use ft8_decodevar
use ft4_decode
use fst4_decode
use q65_decode
+!ft8md added 3 uses below
+ use ft8_mod1, only : ndecodes,allmessages,allsnrs,allfreq,mycall12_0, &
+ mycall12_00,hiscall12_0,nmsg,odd,even,oddcopy,evencopy,nlasttx, &
+ lqsomsgdcd,mycalllen1,msgroot,msgrootlen,lapmyc,sumxdtt,avexdt, &
+ nfawide,nfbwide,mycall,hiscall,lhound,mybcall,hisbcall,lenabledxcsearch, &
+ lwidedxcsearch,hisgrid4,lmultinst,dd8,nft8cycles,lskiptx1,ncandallthr, &
+ nincallthr,incall,msgincall,xdtincall,maskincallthr,ltxing,hisgrid
+
+ use packjt77var, only : lcommonft8b,ihash22,calls12,calls22
+
include 'jt9com.f90'
include 'timer_common.inc'
@@ -30,6 +41,11 @@ subroutine multimode_decoder(ss,id2,params,nfsample) integer :: decoded
end type counting_ft8_decoder
+ type, extends(ft8_decodervar) :: counting_ft8_decodervar
+ integer :: decodedvar
+ real :: xdtt(200)
+ end type counting_ft8_decodervar
+
type, extends(ft4_decoder) :: counting_ft4_decoder
integer :: decoded
end type counting_ft4_decoder
@@ -42,47 +58,68 @@ subroutine multimode_decoder(ss,id2,params,nfsample) integer :: decoded
end type counting_q65_decoder
+ logical first,firstsd !ft8md
+ logical(1) lhoundprev !ft8md
+ integer nutc,ndelay
+ type(params_block) :: params
+ data ndelay/0/
+ data first/.true./ !ft8md
+ data firstsd/.true./ !ft8md
+ data lhoundprev/.false./ !ft8md
real ss(184,NSMAX)
logical baddata,newdat65,newdat9,single_decode,bVHF,bad0,newdat,ex
+ logical lprinthash22
integer*2 id2(NTMAX*12000)
- type(params_block) :: params
+ integer nqf(20)
real*4 dd(NTMAX*12000)
character(len=20) :: datetime
- character(len=12) :: mycall, hiscall
- character(len=6) :: mygrid, hisgrid
+ !character(len=12) :: mycall, hiscall !ft8md
+ character(len=6) :: mygrid!, hisgrid !ft8md
character*60 line
+ character*37 msg37
data ndec8/0/,ntr0/-1/
save
type(counting_jt4_decoder) :: my_jt4
type(counting_jt65_decoder) :: my_jt65
type(counting_jt9_decoder) :: my_jt9
type(counting_ft8_decoder) :: my_ft8
+ type(counting_ft8_decodervar) :: my_ft8var
type(counting_ft4_decoder) :: my_ft4
type(counting_fst4_decoder) :: my_fst4
- type(counting_q65_decoder) :: my_q65
+ type(counting_q65_decoder) :: my_q65
if(.not.params%newdat .and. params%ntr.gt.ntr0) go to 800
ntr0=params%ntr
- rms=sqrt(dot_product(float(id2(1:180000)), &
- float(id2(1:180000)))/180000.0)
- if(rms.lt.3.0) go to 800
+ rms=sqrt(dot_product(float(id2(1:180000)),float(id2(1:180000)))/180000.0)
+ if(rms.lt.0.5) go to 800
- !cast C character arrays to Fortran character strings
+! Cast C character arrays to Fortran character strings
datetime=transfer(params%datetime, datetime)
mycall=transfer(params%mycall,mycall)
+ mybcall=transfer(params%mybcall,mybcall)
hiscall=transfer(params%hiscall,hiscall)
+ hisbcall=transfer(params%hisbcall,hisbcall)
mygrid=transfer(params%mygrid,mygrid)
hisgrid=transfer(params%hisgrid,hisgrid)
+ hisgrid4=hisgrid(1:4)
- ! initialize decode counts
+! Initialize decode counts
my_jt4%decoded = 0
my_jt65%decoded = 0
my_jt9%decoded = 0
my_ft8%decoded = 0
+ my_ft8var%decodedvar = 0
my_ft4%decoded = 0
my_fst4%decoded = 0
my_q65%decoded = 0
+ my_ft8var%xdtt=0.
+
+ ncandall=0 !ft8md
+ ncandallthr=0 !ft8md
+! FT8 defaults at start to enable a8 decoding
+ if(params%nzhsym.eq.41 .or. params%lmultift8) ltry_a8=.true.
+
! For testing only: return Rx messages stored in a file as decodes
inquire(file='rx_messages.txt',exist=ex)
if(ex) then
@@ -104,7 +141,7 @@ subroutine multimode_decoder(ss,id2,params,nfsample) if(mod(params%nranera,2).eq.0) ntrials=10**(params%nranera/2)
if(mod(params%nranera,2).eq.1) ntrials=3*10**(params%nranera/2)
if(params%nranera.eq.0) ntrials=0
-
+
nfail=0
10 if (params%nagain) then
open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown', &
@@ -121,10 +158,9 @@ subroutine multimode_decoder(ss,id2,params,nfsample) endif
if(params%nmode.eq.8) then
-! We're in FT8 mode
-
- if(ncontest.eq.6) then
-! Fox mode: initialize and open houndcallers.txt
+ ! We're in FT8 mode
+ if(ncontest.eq.6) then !Fox=6, Hound=7
+ ! Fox mode: initialize and open houndcallers.txt
inquire(file=trim(temp_dir)//'/houndcallers.txt',exist=ex)
if(.not.ex) then
c2fox=' '
@@ -138,27 +174,987 @@ subroutine multimode_decoder(ss,id2,params,nfsample) open(19,file=trim(temp_dir)//'/houndcallers.txt',status='unknown')
endif
- call timer('decft8 ',0)
- newdat=params%newdat
- if(params%emedelay.ne.0.0) then
- id2(1:156000)=id2(24001:180000) ! Drop the first 2 seconds of data
- id2(156001:180000)=0
- endif
- call my_ft8%decode(ft8_decoded,id2,params%nQSOProgress,params%nfqso, &
- params%nftx,newdat,params%nutc,params%nfa,params%nfb, &
- params%nzhsym,params%ndepth,params%emedelay,ncontest, &
- logical(params%nagain),logical(params%lft8apon), &
- logical(params%lapcqonly),params%napwid,mycall,hiscall, &
- params%ndiskdat)
- call timer('decft8 ',1)
- if(nfox.gt.0) then
- n30min=minval(n30fox(1:nfox))
- n30max=maxval(n30fox(1:nfox))
- endif
- j=0
+ if(ncontest.eq.7 .and. params%b_superfox .and. params%b_even_seq) then
+ if(params%nzhsym.lt.50) go to 800
+ ! Call the superFox decoder
+ call sfrx_sub(params%yymmdd,params%nutc,params%nfqso,params%ntol,id2)
+ else
+ call timer('decft8 ',0)
+ newdat=params%newdat
+ if(params%emedelay.ne.0.0) then
+ id2(1:156000)=id2(24001:180000) ! Drop the first 2 seconds of data
+ id2(156001:180000)=0
+ endif
+
+! ft8md below
+ if(params%lmultift8 .and. params%nmode.eq.8) then
+ if(params%lmodechanged) then
+ avexdt=0.
+ ihash22=-1
+ calls22=''
+ calls12=''
+ nintcount=3
+ endif ! avexdt fast track in FT8 after mode change
+
+ if(.not.params%nagain) ndelay=params%ndelay
+ lqsomsgdcd=.false.
+ if(ndelay.gt.0) then ! received incomplete interval
+ call partintft8(ndelay,params%nutc)
+ lqsomsgdcd=.true.
+ endif
+ ntrials=params%nranera
+ if(params%nsecbandchanged.gt.0) then
+ nsamplesdel=params%nsecbandchanged*12000
+ if(params%nsecbandchanged.gt.14) then
+ dd8=0. ! protection
+ else
+ dd8(1:nsamplesdel)=0.
+ endif
+ endif
+
+ if(.not.params%nagain) nutc=params%nutc
+
+ if(first) then
+ call cwfilter(first)
+ first=.false.
+ endif ! + ALLCALL to memory
+ lenabledxcsearch=params%lenabledxcsearch
+ lwidedxcsearch=params%lwidedxcsearch
+
+ lmultinst=params%lmultinst
+ lskiptx1=params%lskiptx1
+ ltxing=params%ltxing
+
+ mycalllen1=len_trim(mycall)+1
+ msgroot=''
+ msgroot=trim(mycall)//' '//trim(hiscall)//' '
+ msgrootlen=len_trim(msgroot)
+ lcommonft8b=params%lcommonft8b
+ lhound=params%lhound
+ nft8cycles=params%nft8cycles
+ forcedt=0.
+
+ if((hiscall.ne.hiscall12_0 .and. hiscall.ne.' ') &
+ .or. (mycall.ne.mycall12_0 .and. mycall.ne.' ') .or. &
+ (lhound.neqv.lhoundprev)) then
+ if(hiscall.ne.' ') then
+ call tone8(params%lmycallstd,params%lhiscallstd)
+ hiscall12_0=hiscall
+ mycall12_0=mycall
+ endif
+ lhoundprev=lhound
+ endif
+ if(params%lmycallstd .and. mycall.ne.' ' .and. &
+ mycall12_00.ne.mycall) then
+ call tone8myc()
+ mycall12_00=mycall
+ endif
+
+ ndecodes=0 !Initialize arrays for multi-threaded decoding
+ allmessages=""
+ allsnrs=0
+ allfreq=0.
+ numcores=omp_get_num_procs()
+ nuserthr=params%nmt
+
+ numthreads=1 ! fallback
+ if(nuserthr.eq.0) then ! auto
+ if(numcores.eq.1) then
+ numthreads=1
+ else if(numcores.gt.1 .and. numcores.lt.5) then
+ numthreads=numcores-1
+ else if(numcores.gt.4 .and. numcores.lt.9) then
+ numthreads=numcores-2
+ else if(numcores.gt.8 .and. numcores.lt.16) then
+ numthreads=numcores-3
+ else
+ numthreads=12
+ endif
+ else if(nuserthr.gt.0 .and. nuserthr.lt.13) then
+ ! number of threads shall not exceed number of logical cores
+ if(numcores.ge.nuserthr) then
+ numthreads=nuserthr
+ else
+ numthreads=numcores
+ endif
+ endif
+
+ call omp_set_dynamic(.false.)
+ call omp_set_nested(.true.)
+
+ nfa=params%nfa
+ nfb=params%nfb
+ nfqso=params%nfqso
+ nfawide=params%nfa
+ nfbwide=params%nfb
+
+ if(params%nagainfil) then
+ if(nfqso.lt.nfa .or. nfqso.gt.nfb) then
+ write(*,64) nutc,'nfqso is out of bandwidth','d'
+64 format(i6.6,2x,a25,16x,a1)
+ go to 800
+ endif
+ nfa=max(nfa,nfqso-25) ! 50Hz bandwidth for decode via double click
+ nfb=min(nfb,nfqso+25)
+ numthreads=min(4,numthreads)
+! To do: withdraw limitation when threads are in sync at main passes?
+ endif
+
+ nsec=mod(nutc,100)
+ nmsg=0
+ if(nsec.ne.0 .and. nsec.ne.15 .and. nsec.ne.30 .and. nsec.ne.45) then
+! Reading simulated wav file
+ odd%lstate=.false.
+ even%lstate=.false.
+ oddcopy%lstate=.false.
+ evencopy%lstate=.false.
+ endif
+
+ if(firstsd) then
+ odd%lstate=.false.
+ even%lstate=.false.
+ firstsd=.false.
+ endif
+
+ if(nsec.eq.0 .or. nsec.eq.30) then
+ evencopy%msg=even%msg
+ evencopy%freq=even%freq
+ evencopy%dt=even%dt
+ evencopy%lstate=even%lstate
+ even%lstate=.false.
+ endif
+
+ if(nsec.eq.15 .or. nsec.eq.45) then
+ oddcopy%msg=odd%msg
+ oddcopy%freq=odd%freq
+ oddcopy%dt=odd%dt
+ oddcopy%lstate=odd%lstate
+ odd%lstate=.false.
+ endif
+
+ nlasttx=params%nlasttx
+ lapmyc=params%lapmyc
+ nFT8decd=0
+ sumxdt=0.0
+ if(params%nmode.eq.4) sumxdtt=0.0
+ call fillhashvar(numthreads,.false.)
+ call ft8apsetvar(params%lmycallstd,params%lhiscallstd,numthreads)
+
+ if(numthreads.eq.1) then
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress, &
+ nfqso,params%nft8rxfsens,params%nftx,nutc,nfa,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+ endif
+
+ if(numthreads.eq.2) then
+ nfmid=nfa+nint(abs(nfb-nfa)/2.)
+ if((nfmid+1).gt.nfb) nfmid=nfb-1
+
+!$omp parallel sections num_threads(2) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.3) then
+ nfdelta=nint(abs(nfb-nfa)/3.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ if((nfmid2+1).gt.nfb) nfmid2=nfb-1
+!$omp parallel sections num_threads(3) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.4) then
+ nfdelta=nint(abs(nfb-nfa)/4.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ if((nfmid3+1).gt.nfb) nfmid3=nfb-1
+
+!$omp parallel sections num_threads(4) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.5) then
+ nfdelta=nint(abs(nfb-nfa)/5.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ if((nfmid4+1).gt.nfb) nfmid4=nfb-1
+
+!$omp parallel sections num_threads(5) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.6) then
+ nfdelta=nint(abs(nfb-nfa)/6.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ if((nfmid5+1).gt.nfb) nfmid5=nfb-1
+
+!$omp parallel sections num_threads(6) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.7) then
+ nfdelta=nint(abs(nfb-nfa)/7.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ if((nfmid6+1).gt.nfb) nfmid6=nfb-1
+
+!$omp parallel sections num_threads(7) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.8) then
+ nfdelta=nint(abs(nfb-nfa)/8.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ nfmid7=nfmid6+nfdelta
+ if((nfmid7+1).gt.nfb) nfmid7=nfb-1
+
+!$omp parallel sections num_threads(8) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfmid7, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid7+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 8,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.9) then
+ nfdelta=nint(abs(nfb-nfa)/9.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ nfmid7=nfmid6+nfdelta
+ nfmid8=nfmid7+nfdelta
+ if((nfmid8+1).gt.nfb) nfmid8=nfb-1
+
+!$omp parallel sections num_threads(9) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfmid7, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid7+1,nfmid8, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 8,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid8+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 9,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.10) then
+ nfdelta=nint(abs(nfb-nfa)/10.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ nfmid7=nfmid6+nfdelta
+ nfmid8=nfmid7+nfdelta
+ nfmid9=nfmid8+nfdelta
+ if((nfmid9+1).gt.nfb) nfmid9=nfb-1
+
+!$omp parallel sections num_threads(10) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfmid7, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid7+1,nfmid8, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 8,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid8+1,nfmid9, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 9,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid9+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 10,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.11) then
+ nfdelta=nint(abs(nfb-nfa)/11.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ nfmid7=nfmid6+nfdelta
+ nfmid8=nfmid7+nfdelta
+ nfmid9=nfmid8+nfdelta
+ nfmid10=nfmid9+nfdelt
+ if((nfmid10+1).gt.nfb) nfmid10=nfb-1
+!$omp parallel sections num_threads(11) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfmid7, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid7+1,nfmid8, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 8,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid8+1,nfmid9, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 9,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid9+1,nfmid10, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 10,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid10+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 11,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ if(numthreads.eq.12) then
+ nfdelta=nint(abs(nfb-nfa)/12.)
+ nfmid1=nfa+nfdelta
+ nfmid2=nfmid1+nfdelta
+ nfmid3=nfmid2+nfdelta
+ nfmid4=nfmid3+nfdelta
+ nfmid5=nfmid4+nfdelta
+ nfmid6=nfmid5+nfdelta
+ nfmid7=nfmid6+nfdelta
+ nfmid8=nfmid7+nfdelta
+ nfmid9=nfmid8+nfdelta
+ nfmid10=nfmid9+nfdelta
+ nfmid11=nfmid10+nfdelt
+ if((nfmid11+1).gt.nfb) nfmid11=nfb-1
+!$omp parallel sections num_threads(12) shared(dd8,nmsg,even,odd,lqsomsgdcd), &
+!$omp& shared(first_osd,gen,ndecodes,allmessages,allsnrs,allfreq) if(.true.) !iif() needed on Mac
+
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid5+1,nfmid6, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 6,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid6+1,nfmid7, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 7,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid4+1,nfmid5, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 5,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid7+1,nfmid8, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 8,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid3+1,nfmid4, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 4,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid8+1,nfmid9, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 9,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid2+1,nfmid3, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 3,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid9+1,nfmid10, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 10,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid1+1,nfmid2, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 2,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid10+1,nfmid11, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 11,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfa,nfmid1, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 1,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp section
+ call my_ft8var%decodevar(ft8_decodedvar,params%nQSOProgress,nfqso, &
+ params%nft8rxfsens,params%nftx,nutc,nfmid11+1,nfb, &
+ params%ncandthin,params%ndtcenter,nsec,params%napwid, &
+ params%lmycallstd,params%lhiscallstd,params%nstophint, &
+ 12,numthreads,logical(params%nagainfil),params%lft8lowth, &
+ params%lft8subpass,params%lhideft8dupes)
+!$omp end parallel sections
+ endif
+
+ do i=1,numthreads
+ do m=1,nincallthr(i)
+ nindex=maskincallthr(i)+m
+ incall(30:2:-1)=incall(30-1:1:-1)
+ incall(1)%msg=msgincall(nindex)
+ incall(1)%xdt=xdtincall(nindex)
+ enddo
+ enddo
+ if(nsec.eq.0 .or. nsec.eq.30) even(nmsg+1:130)%lstate=.false.
+ if(nsec.eq.15 .or. nsec.eq.45) odd(nmsg+1:130)%lstate=.false.
+
+ if(params%ndelay.eq.0) then
+ nFT8decd=my_ft8var%decodedvar
+ dtmed=0.
+! if(params%lforcesync) then; nintcount=3 ! fast track after Sync
+! elseif(nintcount.gt.0) then; nintcount=nintcount-1
+ if(nintcount.gt.0) then
+ nintcount=nintcount-1
+ endif
+! if(params%lforcesync .and. nFT8decd.eq.0) then
+ if(nFT8decd.eq.0) then
+ avexdt=forcedt
+ else
+ if(nFT8decd.gt.2) then
+ do i=1,nFT8decd
+ if(i.lt.nFT8decd-1) then
+ if((my_ft8var%xdtt(i).gt.my_ft8var%xdtt(i+1) .and. &
+ my_ft8var%xdtt(i).lt.my_ft8var%xdtt(i+2)) .or. &
+ (my_ft8var%xdtt(i).lt.my_ft8var%xdtt(i+1) .and. &
+ my_ft8var%xdtt(i).gt.my_ft8var%xdtt(i+2))) then
+ dtmed=my_ft8var%xdtt(i)
+ else if((my_ft8var%xdtt(i+1).gt.my_ft8var%xdtt(i) .and. &
+ my_ft8var%xdtt(i+1).lt.my_ft8var%xdtt(i+2)) .or. &
+ (my_ft8var%xdtt(i+1).lt.my_ft8var%xdtt(i) .and. &
+ my_ft8var%xdtt(i+1).gt.my_ft8var%xdtt(i+2))) then
+ dtmed=my_ft8var%xdtt(i+1)
+ else if((my_ft8var%xdtt(i+2).gt.my_ft8var%xdtt(i) .and. &
+ my_ft8var%xdtt(i+2).lt.my_ft8var%xdtt(i+1)) .or. &
+ (my_ft8var%xdtt(i+2).lt.my_ft8var%xdtt(i) .and. &
+ my_ft8var%xdtt(i+2).gt.my_ft8var%xdtt(i+1))) then
+ dtmed=my_ft8var%xdtt(i+2)
+ else
+ dtmed=my_ft8var%xdtt(i)
+ endif
+ sumxdt=sumxdt+dtmed
+ else
+ sumxdt=sumxdt+dtmed ! use last median value
+ endif
+ enddo
+ if(nFT8decd.gt.5) then
+ avexdt=(avexdt+sumxdt/nFT8decd)/2
+ else if(nFT8decd.eq.5) then
+ avexdt=(1.1*avexdt+0.9*sumxdt/nFT8decd)/2
+ else if(nFT8decd.eq.4) then
+ avexdt=(1.25*avexdt+0.75*sumxdt/nFT8decd)/2
+ else if(nFT8decd.eq.3) then
+ avexdt=(1.35*avexdt+0.65*sumxdt/nFT8decd)/2
+ endif
+ else if(nFT8decd.gt.0) then
+ sumxdt=sum(my_ft8var%xdtt(1:nFT8decd))
+ if(nFT8decd.eq.2) then
+ avexdt=(1.5*avexdt+0.5*sumxdt/nFT8decd)/2
+ else if(nFT8decd.eq.1) then
+ avexdt=(1.75*avexdt+0.25*sumxdt)/2
+ endif
+ endif
+ endif
+ endif
+
+ if(nFT8decd.gt.10 .and. nintcount.eq.1) avexdt=sumxdt/nFT8decd ! fast track after Sync or mode change on crowded bands
+ call fillhashvar(numthreads,.true.)
+ ncandall=sum(ncandallthr(1:numthreads))
+ if(nFT8decd.eq.0) avexdt=0. ! reset to let correct sliding in decoder
+ call timer('decft8 ',1)
+ else ! still FT8 but not ft8md
+ call my_ft8%decode(ft8_decoded,id2,params%nQSOProgress,params%nfqso, &
+ params%nftx,newdat,params%nutc,params%nfa,params%nfb, &
+ params%nzhsym,params%ndepth,params%emedelay,ncontest, &
+ logical(params%nagain),logical(params%lft8apon),ltry_a8, &
+ logical(params%lapcqonly),params%napwid,mycall,hiscall,hisgrid, &
+ params%ndiskdat)
+ call timer('decft8 ',1)
+ endif ! end of 'still FT8 but not ft8md'
+ endif ! end of 'if not in SuperFox mode'
+
+ j=0
if(ncontest.eq.6) then
-! Fox mode: save decoded Hound calls for possible selection by FoxOp
+ ! Fox mode: save decoded Hound calls for possible selection by FoxOp
+ n=params%nutc
+ n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30
+ if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap
+ n30z=n30
+ n30=n30+nwrap
+
rewind 19
if(nfox.eq.0) then
endfile 19
@@ -166,21 +1162,23 @@ subroutine multimode_decoder(ss,id2,params,nfsample) else
do i=1,nfox
n=n30fox(i)
- if(n30max-n30fox(i).le.4) then
+ nage=min(99,mod(n30-n+288000,2880))
+ if(nage.le.4) then
j=j+1
c2fox(j)=c2fox(i)
g2fox(j)=g2fox(i)
nsnrfox(j)=nsnrfox(i)
nfreqfox(j)=nfreqfox(i)
n30fox(j)=n
- m=n30max-n
+ ! nage=min(99,mod(n30-n+288000,2880))
if(len(trim(g2fox(j))).eq.4) then
call azdist(mygrid,g2fox(j)//' ',0.d0,nAz,nEl,nDmiles, &
nDkm,nHotAz,nHotABetter)
else
nDkm=9999
endif
- write(19,1004) c2fox(j),g2fox(j),nsnrfox(j),nfreqfox(j),nDkm,m
+ write(19,1004) c2fox(j),g2fox(j),nsnrfox(j),nfreqfox(j), &
+ nDkm,nage
1004 format(a12,1x,a4,i5,i6,i7,i3)
endif
enddo
@@ -189,7 +1187,7 @@ subroutine multimode_decoder(ss,id2,params,nfsample) endif
endif
go to 800
- endif
+ endif ! end of code for FT8 mode
if(params%nmode.eq.5) then
call timer('decft4 ',0)
@@ -201,7 +1199,7 @@ subroutine multimode_decoder(ss,id2,params,nfsample) endif
if(params%nmode.eq.66) then !NB: JT65 = 65, Q65 = 66.
-! We're in Q65 mode
+ ! We're in Q65 mode
open(17,file=trim(temp_dir)//'/red.dat',status='unknown')
open(14,file=trim(temp_dir)//'/avemsg.txt',status='unknown')
call timer('dec_q65 ',0)
@@ -211,42 +1209,66 @@ subroutine multimode_decoder(ss,id2,params,nfsample) params%nfa,params%nfb,logical(params%nclearave), &
single_decode,logical(params%nagain),params%max_drift, &
logical(params%newdat),params%emedelay,mycall,hiscall,hisgrid, &
- params%nQSOProgress,ncontest,logical(params%lapcqonly),navg0)
+ params%nQSOProgress,ncontest,logical(params%lapcqonly),navg0,nqf)
+ params%nclearave=.false.
+
+ if(.not.params%nagain) then
+ ! Go through identified candidates again, treating each as if it had been
+ ! double-clicked on the waterfall.
+ do k=1,20
+ if(nqf(k).eq.0) exit
+ if(params%nagain .and. abs(nqf(k)-params%nfqso).gt.params%ntol) cycle
+ nqd=1
+ navg0=0
+ ntol=5
+ call my_q65%decode(q65_decoded,id2,nqd,params%nutc,params%ntr, &
+ params%nsubmode,nqf(k),ntol,params%ndepth, &
+ params%nfa,params%nfb,logical(params%nclearave), &
+ .true.,.true.,params%max_drift, &
+ .false.,params%emedelay,mycall,hiscall,hisgrid, &
+ params%nQSOProgress,ncontest,logical(params%lapcqonly), &
+ navg0,nqf)
+ enddo
+ endif
+
call timer('dec_q65 ',1)
close(17)
go to 800
endif
if(params%nmode.eq.240) then
-! We're in FST4 mode
+ ! We're in FST4 mode
ndepth=iand(params%ndepth,3)
iwspr=0
+ lprinthash22=.false.
params%nsubmode=0
call timer('dec_fst4',0)
call my_fst4%decode(fst4_decoded,id2,params%nutc, &
params%nQSOProgress,params%nfa,params%nfb, &
params%nfqso,ndepth,params%ntr,params%nexp_decode, &
params%ntol,params%emedelay,logical(params%nagain), &
- logical(params%lapcqonly),mycall,hiscall,iwspr)
+ logical(params%lapcqonly),mycall,hiscall,iwspr,lprinthash22)
call timer('dec_fst4',1)
go to 800
endif
- if(params%nmode.eq.241) then
-! We're in FST4W mode
+ if(params%nmode.eq.241 .or. params%nmode.eq.242) then
+ ! We're in FST4W mode
ndepth=iand(params%ndepth,3)
iwspr=1
+ lprinthash22=.false.
+ if(params%nmode.eq.242) lprinthash22=.true.
call timer('dec_fst4',0)
call my_fst4%decode(fst4_decoded,id2,params%nutc, &
params%nQSOProgress,params%nfa,params%nfb, &
params%nfqso,ndepth,params%ntr,params%nexp_decode, &
params%ntol,params%emedelay,logical(params%nagain), &
- logical(params%lapcqonly),mycall,hiscall,iwspr)
+ logical(params%lapcqonly),mycall,hiscall,iwspr,lprinthash22)
call timer('dec_fst4',1)
go to 800
endif
-! Zap data at start that might come from T/R switching transient?
+ ! Zap data at start that might come from T/R switching transient?
nadd=100
k=0
bad0=.false.
@@ -265,9 +1287,9 @@ subroutine multimode_decoder(ss,id2,params,nfsample) enddo
if(bad0) then
nz=min(NTMAX*12000,kbad+100)
-! id2(1:nz)=0 ! temporarily disabled as it can breaak the JT9 decoder, maybe others
+ ! id2(1:nz)=0 ! temporarily disabled as it can breaak the JT9 decoder, maybe others
endif
-
+
if(params%nmode.eq.4 .or. params%nmode.eq.65) open(14,file=trim(temp_dir)// &
'/avemsg.txt',status='unknown')
@@ -293,18 +1315,17 @@ subroutine multimode_decoder(ss,id2,params,nfsample) ndecoded=0
go to 800
endif
-
+
ntol65=params%ntol !### is this OK? ###
newdat65=params%newdat
newdat9=params%newdat
-!$call omp_set_dynamic(.true.)
-!$omp parallel sections num_threads(2) copyin(/timer_private/) shared(ndecoded) if(.true.) !iif() needed on Mac
+ call omp_set_dynamic(.true.)
-!$omp section
- if(params%nmode.eq.65) then
-! We're in JT65 mode
+!$omp parallel sections num_threads(2) shared(ndecoded) if(.true.) !iif() needed on Mac
+!$omp section
+ if(params%nmode.eq.65) then ! We're in JT65 mode
if(newdat65) dd(1:npts65)=id2(1:npts65)
nf1=params%nfa
nf2=params%nfb
@@ -313,15 +1334,16 @@ subroutine multimode_decoder(ss,id2,params,nfsample) nf1,nf2,params%nfqso,ntol65,params%nsubmode,params%minsync, &
logical(params%nagain),params%n2pass,logical(params%nrobust), &
ntrials,params%naggressive,params%ndepth,params%emedelay, &
- logical(params%nclearave),mycall,hiscall, &
- hisgrid,params%nexp_decode,params%nQSOProgress, &
+ logical(params%nclearave),mycall,hiscall, &
+ hisgrid,params%nexp_decode,params%nQSOProgress, &
logical(params%ljt65apon))
call timer('jt65a ',1)
- else if(params%nmode.eq.9 .or. (params%nmode.eq.(65+9) .and. params%ntxmode.eq.9)) then
-! We're in JT9 mode, or should do JT9 first
+ else if(params%nmode.eq.9 .or. (params%nmode.eq.(65+9) .and. &
+ params%ntxmode.eq.9)) then
+ ! We're in JT9 mode, or should do JT9 first
call timer('decjt9 ',0)
- call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, &
+ call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, &
newdat9,params%npts8,params%nfa,params%nfsplit,params%nfb, &
params%ntol,params%nzhsym,logical(params%nagain),params%ndepth, &
params%nmode,params%nsubmode,params%nexp_decode)
@@ -355,19 +1377,31 @@ subroutine multimode_decoder(ss,id2,params,nfsample) !$omp end parallel sections
+
! JT65 is not yet producing info for nsynced, ndecoded.
800 ndecoded = my_jt4%decoded + my_jt65%decoded + my_jt9%decoded + &
- my_ft8%decoded + my_ft4%decoded + my_fst4%decoded + &
- my_q65%decoded
- if(params%nmode.eq.8 .and. params%nzhsym.eq.41) ndec41=ndecoded
- if(params%nmode.eq.8 .and. params%nzhsym.eq.47) ndec47=ndecoded
- if(params%nmode.eq.8 .and. params%nzhsym.eq.50) then
+ my_ft8%decoded + my_ft8var%decodedvar + my_ft4%decoded + &
+ my_fst4%decoded + my_q65%decoded
+ if(params%lmultift8 .and. params%nmode.eq.8) then
+ if(params%nzhsym.eq.41) ndec41=0
+ if(params%nzhsym.eq.46) ndec46=ndecoded
+ if(params%nzhsym.eq.47) ndec47=ndecoded
+ if(params%nzhsym.eq.48) ndec48=ndecoded
+ if(params%nzhsym.eq.49) ndec49=ndecoded
+ if(params%nzhsym.eq.50) then
+ ndecoded=ndec41+ndec46+ndec47+ndec48+ndec49+ndecoded
+ endif
+ elseif(params%nmode.eq.8 .and. params%nzhsym.eq.41) then
+ ndec41=ndecoded
+ elseif(params%nmode.eq.8 .and. params%nzhsym.eq.47) then
+ ndec47=ndecoded
+ elseif(params%nmode.eq.8 .and. params%nzhsym.eq.50) then
ndecoded=ndec41+ndec47+ndecoded
endif
- if(params%nmode.ne.8 .or. params%nzhsym.eq.50 .or. &
- .not.params%ndiskdat) then
-
- write(*,1010) nsynced,ndecoded,navg0
+ if(params%nmode.ne.8 .or. params%nzhsym.eq.50 .or. &
+ (params%lmultift8 .and. params%nmode.eq.8 .and. params%nzhsym.gt.45) .or. &
+ .not.params%ndiskdat) then !ft8md
+ if(.not.lquiet) write(*,1010) nsynced,ndecoded,navg0
1010 format('<DecodeFinished>',2i4,i9)
call flush(6)
endif
@@ -375,6 +1409,7 @@ subroutine multimode_decoder(ss,id2,params,nfsample) if(ncontest.eq.6) close(19)
if(params%nmode.eq.4 .or. params%nmode.eq.65 .or. params%nmode.eq.66) close(14)
return
+
contains
subroutine jt4_decoded(this,snr,dt,freq,have_sync,sync,is_deep, &
@@ -470,8 +1505,7 @@ contains logical is_deep,is_average
character decoded*22,csync*2,cflags*3
- if(width.eq.-9999.0) stop !Silence compiler warning
-!$omp critical(decode_results)
+ !$omp critical(decode_results)
decoded=decoded0
cflags=' '
is_deep=ft.eq.2
@@ -528,13 +1562,13 @@ contains 1012 format(i4.4,i4,i5,f6.2,f8.0,i4,3x,a22,' JT65',3i3)
call flush(6)
-!$omp end critical(decode_results)
+ !$omp end critical(decode_results)
select type(this)
type is (counting_jt65_decoder)
this%decoded = this%decoded + 1
end select
end subroutine jt65_decoded
-
+
subroutine jt9_decoded (this, sync, snr, dt, freq, drift, decoded)
use jt9_decode
implicit none
@@ -548,6 +1582,7 @@ contains character(len=22), intent(in) :: decoded
!$omp critical(decode_results)
+
write(*,1000) params%nutc,snr,dt,nint(freq),decoded
1000 format(i4.4,i4,f5.1,i5,1x,'@ ',1x,a22)
if(ios13.eq.0) write(13,1002) params%nutc,nint(sync),snr,dt,freq, &
@@ -561,6 +1596,117 @@ contains end select
end subroutine jt9_decoded
+ subroutine ft8_decodedvar (this,snr,dt,freq,decodedvar,nap,qual) !ft8md was(this,snr,dt,freq,decodedvar)
+ use ft8_decodevar
+ implicit none
+
+ class(ft8_decodervar), intent(inout) :: this
+ integer, intent(in) :: snr
+ real, intent(in) :: dt
+ real, intent(in) :: freq
+ real, intent(in) :: qual
+ real fdiff
+ character(len=37), intent(in) :: decodedvar !ft8md was 26
+ character*3 annot !ft8md was 2
+ character c1*12,c2*12,g2*4,w*4
+ integer i1,i2,i3,i4,i5,n30,nwrap
+ integer, intent(in) :: nap !ft8md
+ integer msglen
+ character*43 decoded0
+ logical isgrid4,first,b0,b1,b2
+ data first/.true./
+ save
+
+ isgrid4(w)=(len_trim(w).eq.4 .and. &
+ ichar(w(1:1)).ge.ichar('A') .and. ichar(w(1:1)).le.ichar('R') .and. &
+ ichar(w(2:2)).ge.ichar('A') .and. ichar(w(2:2)).le.ichar('R') .and. &
+ ichar(w(3:3)).ge.ichar('0') .and. ichar(w(3:3)).le.ichar('9') .and. &
+ ichar(w(4:4)).ge.ichar('0') .and. ichar(w(4:4)).le.ichar('9'))
+
+ if(first) then
+ c2fox=' '
+ g2fox=' '
+ nsnrfox=-99
+ nfreqfox=-99
+ n30z=0
+ nwrap=0
+ nfox=0
+ first=.false.
+ endif
+
+ fdiff=freq-params%nfqso
+ if(abs(fdiff).lt.3.0) ltry_a8=.false.
+
+ decoded0=trim(decodedvar)
+ annot=' '
+ if(nap.ne.0) then
+ msglen = len_trim(decoded0)
+ write(annot,'(a1,i0)') 'a',nap
+ if(qual.lt.0.17) then
+ if(msglen.lt.19) then
+ decoded0(20:20) = '?'
+ decoded0 = trim(decoded0) // ' ' // trim(annot)
+ else
+ decoded0 = trim(decoded0) // ' ?'
+ decoded0 = trim(decoded0) // ' ' // trim(annot)
+ endif
+ else
+ if(msglen.lt.19) then
+ decoded0 = decoded0(1:20) // ' ' // trim(annot)
+ else
+ decoded0 = trim(decoded0) // ' ' // trim(annot)
+ endif
+ endif
+ endif
+
+ write(*,1000) params%nutc,snr,dt,nint(freq),decoded0
+1000 format(i6.6,i4,f5.1,i5,' ~ ',1x,a43,1x) ! was a26
+
+ if(ncontest.eq.6) then
+ i1=index(decoded0,' ')
+ i2=i1 + index(decoded0(i1+1:),' ')
+ i3=i2 + index(decoded0(i2+1:),' ')
+ if(i1.ge.3 .and. i2.ge.7 .and. i3.ge.10) then
+ c1=decoded0(1:i1-1)//' '
+ c2=decoded0(i1+1:i2-1)
+ g2=decoded0(i2+1:i3-1)
+ b0=c1.eq.mycall
+ if(c1(1:3).eq.'DE ' .and. index(c2,'/').ge.2) b0=.true.
+ if(len(trim(c1)).ne.len(trim(mycall))) then
+ i4=index(trim(c1),trim(mycall))
+ i5=index(trim(mycall),trim(c1))
+ if(i4.ge.1 .or. i5.ge.1) b0=.true.
+ endif
+ b1=i3-i2.eq.5 .and. isgrid4(g2)
+ b2=i3-i2.eq.1
+ if(b0 .and. (b1.or.b2) .and. (nint(freq).ge.1000 .or. &
+ params%b_superfox)) then
+ n=params%nutc
+ n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30
+ if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap
+ n30z=n30
+ n30=n30+nwrap
+ if(nfox.lt.MAXFOX) nfox=nfox+1
+ c2fox(nfox)=c2
+ g2fox(nfox)=g2
+ nsnrfox(nfox)=snr
+ nfreqfox(nfox)=nint(freq)
+ n30fox(nfox)=n30
+ endif
+ endif
+ endif
+ call flush(6)
+ if(ios13.eq.0) call flush(13)
+
+ select type(this)
+ type is (counting_ft8_decodervar)
+ this%decodedvar = this%decodedvar + 1
+ this%xdtt(this%decodedvar)=dt
+ end select
+
+ return
+ end subroutine ft8_decodedvar
+
subroutine ft8_decoded (this,sync,snr,dt,freq,decoded,nap,qual)
use ft8_decode
implicit none
@@ -574,7 +1720,8 @@ contains character c1*12,c2*12,g2*4,w*4
integer i0,i1,i2,i3,i4,i5,n30,nwrap
integer, intent(in) :: nap
- real, intent(in) :: qual
+ real, intent(in) :: qual
+ real fdiff
character*2 annot
character*37 decoded0
logical isgrid4,first,b0,b1,b2
@@ -597,19 +1744,21 @@ contains nfox=0
first=.false.
endif
-
+
decoded0=decoded
+ fdiff=freq-params%nfqso
+ if(abs(fdiff).lt.3.0) ltry_a8=.false.
- annot=' '
+ annot=' '
if(nap.ne.0) then
write(annot,'(a1,i1)') 'a',nap
if(qual.lt.0.17) decoded0(37:37)='?'
endif
-! i0=index(decoded0,';')
-! Always print 37 characters? Or, send i3,n3 up to here from ft8b_2 and use them
-! to decide how many chars to print?
-!TEMP
+ ! i0=index(decoded0,';')
+ ! Always print 37 characters? Or, send i3,n3 up to here from ft8b_2 and use them
+ ! to decide how many chars to print?
+ !TEMP
i0=1
if(i0.le.0) write(*,1000) params%nutc,snr,dt,nint(freq),decoded0(1:22),annot
1000 format(i6.6,i4,f5.1,i5,' ~ ',1x,a22,1x,a2)
@@ -635,10 +1784,11 @@ contains endif
b1=i3-i2.eq.5 .and. isgrid4(g2)
b2=i3-i2.eq.1
- if(b0 .and. (b1.or.b2) .and. nint(freq).ge.1000) then
+ if(b0 .and. (b1.or.b2) .and. (nint(freq).ge.1000 .or. &
+ params%b_superfox)) then
n=params%nutc
n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30
- if(n30.lt.n30z) nwrap=nwrap+5760 !New UTC day, handle the wrap
+ if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap
n30z=n30
n30=n30+nwrap
if(nfox.lt.MAXFOX) nfox=nfox+1
@@ -650,15 +1800,15 @@ contains endif
endif
endif
-
+
call flush(6)
if(ios13.eq.0) call flush(13)
-
+
select type(this)
type is (counting_ft8_decoder)
this%decoded = this%decoded + 1
end select
-
+
return
end subroutine ft8_decoded
@@ -676,7 +1826,7 @@ contains real, intent(in) :: qual
character*2 annot
character*37 decoded0
-
+
decoded0=decoded
annot=' '
@@ -693,9 +1843,9 @@ contains 1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FT4')
flush(13)
endif
-
+
10 call flush(6)
-
+
select type(this)
type is (counting_ft4_decoder)
this%decoded = this%decoded + 1
@@ -705,7 +1855,7 @@ contains end subroutine ft4_decoded
subroutine fst4_decoded (this,nutc,sync,nsnr,dt,freq,decoded,nap, &
- qual,ntrperiod,lwspr,fmid,w50)
+ qual,ntrperiod,fmid,w50)
use fst4_decode
implicit none
@@ -720,7 +1870,6 @@ contains integer, intent(in) :: nap
real, intent(in) :: qual
integer, intent(in) :: ntrperiod
- logical, intent(in) :: lwspr
real, intent(in) :: fmid
real, intent(in) :: w50
@@ -763,11 +1912,11 @@ contains this%decoded = this%decoded + 1
end select
- return
- end subroutine fst4_decoded
+ return
+ end subroutine fst4_decoded
- subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, &
- nused,ntrperiod)
+ subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, &
+ nused,ntrperiod)
use q65_decode
implicit none
@@ -783,7 +1932,7 @@ contains integer, intent(in) :: nused
integer, intent(in) :: ntrperiod
character*3 cflags
-
+
cflags=' '
if(idec.ge.0) then
cflags='q '
@@ -794,8 +1943,8 @@ contains if(ntrperiod.lt.60) then
write(*,1001) nutc,nsnr,dt,nint(freq),decoded,cflags
1001 format(i6.6,i4,f5.1,i5,' : ',1x,a37,1x,a3)
- if(ios13.eq.0) write(13,1002) nutc,nint(snr1),nsnr,dt,freq,0,decoded
-1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65')
+ if(ios13.eq.0) write(13,1002) nutc,nint(snr1),nsnr,dt,freq,0,decoded
+1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65')
else
write(*,1003) nutc,nsnr,dt,nint(freq),decoded,cflags
1003 format(i4.4,i4,f5.1,i5,' : ',1x,a37,1x,a3)
@@ -811,7 +1960,7 @@ contains if(idec.ge.0) this%decoded = this%decoded + 1
end select
- return
- end subroutine q65_decoded
+ return
+ end subroutine q65_decoded
end subroutine multimode_decoder
diff --git a/lib/env_module.f90 b/lib/env_module.f90 new file mode 100755 index 00000000..7feb49de --- /dev/null +++ b/lib/env_module.f90 @@ -0,0 +1,80 @@ +module env_module
+ implicit none
+ integer, parameter :: max_path_length = 4096
+
+contains
+ logical function is_windows()
+ implicit none
+ character(len=256) :: appData
+ integer :: length, status
+ integer :: i
+
+ ! Initialize the function result to false
+ is_windows = .false.
+
+ ! Retrieve the APPDATA environment variable
+ call get_environment_variable('APPDATA', appData, length, status)
+
+ ! Check if the environment variable was successfully retrieved
+ if (status == 0) then
+ ! Look for a backslash in the APPDATA variable
+ do i = 1, length
+ if (appData(i:i) == '\') then
+ is_windows = .true.
+ exit
+ end if
+ end do
+ end if
+ end function is_windows
+
+ subroutine get_executable_directory(executable_directory)
+ implicit none
+ character(len=max_path_length), intent(out) :: executable_directory
+ character(len=max_path_length) :: full_path, temp_directory
+ integer :: length, status, last_sep
+ integer :: i, j
+ logical :: win
+
+ ! Retrieve the command argument 0, which is the path to the executable
+ call get_command_argument(0, full_path, length, status)
+ if (status /= 0) then
+ executable_directory = 'Unknown'
+ else
+ full_path = full_path(1:length)
+
+ ! Find the last directory separator
+ last_sep = 0
+ do i = length, 1, -1
+ if (full_path(i:i) == '/' .or. full_path(i:i) == '\') then
+ last_sep = i
+ exit
+ end if
+ end do
+
+ ! Extract the directory part
+ if (last_sep > 0) then
+ executable_directory = full_path(1:last_sep-1)
+ else
+ executable_directory = '.'
+ end if
+
+ ! Check if the OS is not Windows and escape spaces if needed
+ win = is_windows()
+ if (.not. win) then
+ temp_directory = ''
+ j = 1
+ do i = 1, len_trim(executable_directory)
+ if (executable_directory(i:i) == ' ') then
+ temp_directory(j:j+1) = '\ '
+ j = j + 2
+ else
+ temp_directory(j:j) = executable_directory(i:i)
+ j = j + 1
+ end if
+ end do
+ executable_directory = temp_directory
+ end if
+ end if
+ end subroutine get_executable_directory
+end module env_module
+
diff --git a/lib/four2a.f90 b/lib/four2a.f90 index 93d713c0..9acbc0be 100755 --- a/lib/four2a.f90 +++ b/lib/four2a.f90 @@ -20,7 +20,7 @@ subroutine four2a(a,nfft,ndim,isign,iform) ! actual computations.
use fftw3
- parameter (NPMAX=2100) !Max numberf of stored plans
+ parameter (NPMAX=2100) !Max number of stored plans
parameter (NSMALL=16385) !Max half complex size of "small" FFTs
complex a(nfft) !Array to be transformed
complex aa(NSMALL) !Local copy of "small" a()
diff --git a/lib/fst4/fastosd240_74.f90 b/lib/fst4/fastosd240_74.f90 index e7256a98..843fb9e2 100755 --- a/lib/fst4/fastosd240_74.f90 +++ b/lib/fst4/fastosd240_74.f90 @@ -168,18 +168,19 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) if(ndeep.eq.0) goto 998 ! norder=0
if(ndeep.gt.4) ndeep=4
+ nsyndmax=0
if( ndeep.eq. 1) then
nord=1
xlambda=0.0
- nsyncmax=np
+ nsyndmax=np
elseif(ndeep.eq.2) then
nord=2
xlambda=0.0
- nsyncmax=np
+ nsyndmax=np
elseif(ndeep.eq.3) then
nord=3
xlambda=4.0
- nsyncmax=11
+ nsyndmax=11
elseif(ndeep.eq.4) then
nord=4
xlambda=3.4
@@ -190,7 +191,6 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) s2=sum(absrx(k+1:N))
rho=s1/(s1+xlambda*s2)
rhodmin=rho*dmin
- nerr64=-1
do iorder=1,nord
!beta=0.0
!if(iorder.ge.3) beta=0.4
@@ -216,7 +216,6 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) cw=ce
nhardmin=sum(nxor)
nwhspmin=nwhsp
- nerr64=sum(nxor(1:K))
endif
endif
! Get the next test error pattern, iflag will go negative
@@ -224,7 +223,6 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) call nextpat74(mi,k,iorder,iflag)
enddo
enddo
-
998 continue
! Re-order the codeword to [message bits][parity bits] format.
cw(indices)=cw
diff --git a/lib/fst4/fst4sim.f90 b/lib/fst4/fst4sim.f90 index 8ae7ec70..4bb85f42 100755 --- a/lib/fst4/fst4sim.f90 +++ b/lib/fst4/fst4sim.f90 @@ -93,6 +93,10 @@ program fst4sim if(i3.eq.1) then
write(*,*) ' mycall hiscall hisgrid'
write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77)
+ elseif(i3.eq.0 .and. n3.eq.6) then
+ write(*,'(a15,37x,a5)') '50-bit message','CRC24'
+ write(*,'(50i1,1x,24i1)') msgbits(1:50),msgbits(51:74)
+ write(*,'(a50)') '01234567890123456789012345678901234567890123456789'
else
write(*,'(a14)') 'Message bits: '
write(*,'(77i1,1x,24i1)') msgbits
diff --git a/lib/fst4/ldpcsim240_74.f90 b/lib/fst4/ldpcsim240_74.f90 index c9135a88..c2bc37ba 100755 --- a/lib/fst4/ldpcsim240_74.f90 +++ b/lib/fst4/ldpcsim240_74.f90 @@ -4,33 +4,47 @@ program ldpcsim240_74 use packjt77
- parameter(N=240, K=74, M=N-K)
+ parameter(N=240, NN=120)
character*8 arg
character*37 msg0
character*77 c77
character*24 c24
- integer*1 msgbits(74)
+ integer*1 msgbits(101)
integer*1 apmask(240)
integer*1 cw(240)
integer*1 codeword(N),message74(74)
integer ncrc24
- real rxdata(N),llr(N)
+ integer modtype, graymap(0:3)
+ integer*4 itone(120)
+ integer channeltype
+ integer lmax(1)
+ real rxdata(N)
+ real llr(240)
+ real bitmetrics(2*NN,4)
+ complex c1(4,8),c2(16,4),c4(256,2),cs(0:3,NN)
+ real s2(0:65535)
+ logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits
logical first
data first/.true./
+ data graymap/0,1,3,2/
nargs=iargc()
- if(nargs.ne.5 .and. nargs.ne.6) then
- print*,'Usage: ldpcsim niter ndeep #trials s K [msg]'
- print*,'e.g. ldpcsim240_74 20 5 1000 0.85 64 "K9AN K1JT FN20"'
+ if(nargs.ne.7 .and. nargs.ne.8) then
+ print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel '
+ print*,'e.g. ldpcsim240_74 2 4 1000 0.85 50 1 0'
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 [50,74]'
+ print*,'maxosd<0: do bp only'
+ print*,'maxosd=0: do bp and then call osd once with channel llrs.'
+ print*,'maxosd>0: do bp and then call osc maxosd times with saved bp outputs.'
+ print*,'norder : osd decoding depth'
+ print*,'Keff : # of message bits, Keff must be in the range 50:74'
+ print*,'modtype : 0 coherent BPSK, 1 4FSK'
+ print*,'channel : 0 AWGN, 1 Rayleigh (4FSK only)'
print*,'WSPR-format message is optional'
return
endif
call getarg(1,arg)
- read(arg,*) max_iterations
+ read(arg,*) maxosd
call getarg(2,arg)
read(arg,*) norder
call getarg(3,arg)
@@ -39,17 +53,26 @@ program ldpcsim240_74 read(arg,*) s
call getarg(5,arg)
read(arg,*) Keff
- msg0='K9AN K1JT FN20 '
- if(nargs.eq.6) call getarg(6,msg0)
+ call getarg(6,arg)
+ read(arg,*) modtype
+ call getarg(7,arg)
+ read(arg,*) channeltype
+ call getarg(8,arg)
+
+ msg0='K9AN EN50 20 '
call pack77(msg0,i3,n3,c77)
rate=real(Keff)/real(N)
write(*,*) "code rate: ",rate
- write(*,*) "niter : ",max_iterations
+ write(*,*) "maxosd : ",maxosd
write(*,*) "norder : ",norder
write(*,*) "s : ",s
write(*,*) "K : ",Keff
+ if(modtype.eq.0) write(*,*) "modtype : coherent BPSK"
+ if(modtype.eq.1) write(*,*) "modtype : noncoherent 4FSK"
+ if(channeltype.eq.0) write(*,*) "channel : AWGN"
+ if(channeltype.eq.1) write(*,*) "channel : Rayleigh"
msgbits=0
read(c77,'(50i1)') msgbits(1:50)
@@ -59,49 +82,171 @@ program ldpcsim240_74 call get_crc24(msgbits,74,ncrc24)
write(c24,'(b24.24)') ncrc24
read(c24,'(24i1)') msgbits(51:74)
-write(*,'(24i1)') msgbits(51:74)
+ write(*,'(24i1)') msgbits(51:74)
write(*,*) 'message with crc24'
write(*,'(74i1)') msgbits(1:74)
- call encode240_74(msgbits,codeword)
- call init_random_seed()
- call sgran()
+
+ call encode240_74(msgbits(1:74),codeword)
+ do i=1,120
+ is=codeword(2*i)+2*codeword(2*i-1)
+ itone(i)=graymap(is)
+ enddo
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
+! call init_random_seed()
+! call sgran()
+
+ iq=1
+ one=.false.
+ do i=0,65535
+ do j=0,15
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
+
+ write(*,*) "Eb/N0 Es/N0 ngood nundetected symbol error rate"
+ do idb = 24,-8,-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*rate*iq*(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
+ nsymerr=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
+ if(modtype.eq.0) then
+ iq = 1 ! bits per symbol
+ sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No
+ 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)
else
- ss=s
+! noncoherent MFSK
+ iq = 2 ! bits per symbol
+ sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No
+ A=1
+ do i=1,120
+ do j=0,3
+ if(j.eq.itone(i)) then
+ if(channeltype.eq.0) then
+ A=1.0
+ elseif(channeltype.eq.1) then
+ xI=gran()**2+gran()**2
+ A=sqrt(xI/2)
+ endif
+ cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran()
+ elseif(j.ne.itone(i)) then
+ cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran()
+ endif
+ enddo
+ lmax=maxloc(abs(cs(:,i)))
+ if(lmax(1)-1.ne.itone(i) ) nsymerr=nsymerr+1
+ enddo
+
+ do k=1,NN,8
+
+ do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs
+ s2=0
+ do is=1,4
+ c1(is,m)=cs(graymap(is-1),k+m-1)
+ s2(is-1)=abs(c1(is,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))
+ 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))**2
+ 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))
+ 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))
+ 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))
+ 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
+ do i=1,256
+ do j=1,256
+ is=(i-1)*256+j
+ 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))
+ if(ipt+ib.gt.2*NN) cycle
+ bitmetrics(ipt+ib,4)=bm
+ enddo
+
+ enddo
+
+ call normalizebmet(bitmetrics(:,1),2*NN)
+ call normalizebmet(bitmetrics(:,2),2*NN)
+ call normalizebmet(bitmetrics(:,3),2*NN)
+ call normalizebmet(bitmetrics(:,4),2*NN)
+
+ scalefac=2.83
+ bitmetrics=scalefac*bitmetrics
+
+ llr=bitmetrics(:,1)
endif
- llr=2.0*rxdata/(ss*ss)
apmask=0
dmin=0.0
- maxosd=2
call decode240_74(llr, Keff, maxosd, norder, apmask, message74, cw, ntype, nharderror, dmin)
if(nharderror.ge.0) then
n2err=0
@@ -116,9 +261,10 @@ write(*,'(24i1)') msgbits(51:74) 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,e10.3)") db,esn0,ngood,nue,pberr
+ esn0=db+10*log10(rate*iq)
+ pberr=real(nberr)/real(ntrials*N)
+ pserr=real(nsymerr)/real(ntrials*120)
+ write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,e10.3)") db,esn0,ngood,nue,pserr
enddo
diff --git a/lib/fst4_decode.f90 b/lib/fst4_decode.f90 index d3b8af73..f2ccd2da 100755 --- a/lib/fst4_decode.f90 +++ b/lib/fst4_decode.f90 @@ -8,7 +8,7 @@ module fst4_decode abstract interface
subroutine fst4_decode_callback (this,nutc,sync,nsnr,dt,freq, &
- decoded,nap,qual,ntrperiod,lwspr,fmid,w50)
+ decoded,nap,qual,ntrperiod,fmid,w50)
import fst4_decoder
implicit none
class(fst4_decoder), intent(inout) :: this
@@ -21,7 +21,6 @@ module fst4_decode integer, intent(in) :: nap
real, intent(in) :: qual
integer, intent(in) :: ntrperiod
- logical, intent(in) :: lwspr
real, intent(in) :: fmid
real, intent(in) :: w50
end subroutine fst4_decode_callback
@@ -31,7 +30,7 @@ contains subroutine decode(this,callback,iwave,nutc,nQSOProgress,nfa,nfb,nfqso, &
ndepth,ntrperiod,nexp_decode,ntol,emedelay,lagain,lapcqonly,mycall, &
- hiscall,iwspr)
+ hiscall,iwspr,lprinthash22)
use prog_args
use timer_module, only: timer
@@ -67,9 +66,10 @@ contains integer mcq(29),mrrr(19),m73(19),mrr73(19)
logical badsync,unpk77_success,single_decode
- logical first,nohiscall,lwspr
+ logical first,nohiscall
logical new_callsign,plotspec_exists,wcalls_exists,do_k50_decode
logical decdata_exists
+ logical lprinthash22
integer*2 iwave(30*60*12000)
@@ -88,7 +88,8 @@ contains dxcall13=hiscall ! initialize for use in packjt77
mycall13=mycall
- if(iwspr.ne.0.and.iwspr.ne.1) return
+ if(iwspr.ne.0 .and. iwspr.ne.1) return
+
if(lagain) continue ! use lagain to keep compiler happy
if(first) then
@@ -503,6 +504,13 @@ contains write(c77,'(50i1)') message74(1:50)
c77(51:77)='000000000000000000000110000'
call unpack77(c77,1,msg,unpk77_success)
+ if(lprinthash22 .and. unpk77_success .and. index(msg,'<...>').gt.0) then
+ read(c77,'(b22.22)') n22tmp
+ i1=index(msg,' ')
+ wpart=trim(msg(i1+1:))
+ write(msg,'(a1,i7.7,a1)') '<',n22tmp,'>'
+ msg=trim(msg)//' '//trim(wpart)
+ endif
if(unpk77_success .and. do_k50_decode) then
! If decode was obtained with Keff=66, save call/grid in fst4w_calls.txt if not there already.
i1=index(msg,' ')
@@ -602,6 +610,7 @@ contains case(1800)
snr_calfac=320.0
case default
+ snr_calfac=430.0
end select
arg=snr_calfac*xsig/base - 1.0
if(arg.gt.0.0) then
@@ -626,8 +635,7 @@ contains close(21)
endif
call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, &
- iaptype,qual,ntrperiod,lwspr,fmid,w50)
-! if(iwspr.eq.0 .and. nb.lt.0) go to 900
+ iaptype,qual,ntrperiod,fmid,w50)
goto 800
endif
enddo ! metrics
@@ -988,7 +996,7 @@ contains do i=-ia,ia !Find freq range that has 50% of signal power
sum2=sum2 + ss(i)-avg
if(sum2.ge.0.25*sum1 .and. xi1.eq.-999.0) then
- xi1=i - 1 + (sum2-0.25*sum1)/(sum2-sum2z)
+ xi1=i - 1 + (0.25*sum1-sum2)/(sum2-sum2z)
endif
if(sum2.ge.0.50*sum1 .and. xi2.eq.-999.0) then
xi2=i - 1 + (sum2-0.50*sum1)/(sum2-sum2z)
diff --git a/lib/ft4/ft4code.f90 b/lib/ft4/ft4code.f90 index 51b16460..ac3d9892 100755 --- a/lib/ft4/ft4code.f90 +++ b/lib/ft4/ft4code.f90 @@ -26,8 +26,8 @@ program ft4code 'LDPC(174,91) encoding,'
print*,'bit and symbol ordering, and other details of the FT4 protocol.'
print*
- print*,'Usage: ft4code [-c grid] "message" # Results for specified message'
- print*,' ft4code -t # Examples of all message types'
+ print*,'Usage: ft4code "message" # Results for specified message'
+ print*,' ft4code -t # Examples of all message types'
go to 999
endif
diff --git a/lib/ft4_decode.f90 b/lib/ft4_decode.f90 index 2ff3a767..a562ff93 100755 --- a/lib/ft4_decode.f90 +++ b/lib/ft4_decode.f90 @@ -28,7 +28,7 @@ contains use timer_module, only: timer
use packjt77
include 'ft4/ft4_params.f90'
- parameter (MAXCAND=100)
+ parameter (MAXCAND=200)
class(ft4_decoder), intent(inout) :: this
procedure(ft4_decode_callback) :: callback
parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN)
@@ -192,7 +192,7 @@ contains ! ndepth=1: 1 pass, no subtraction
max_iterations=40
- syncmin=1.2
+ syncmin=1.18
dosubtract=.true.
doosd=.true.
nsp=3
@@ -349,7 +349,7 @@ contains ! 7 : HOUND
!
! Conditions that cause us to bail out of AP decoding
- napwid=80
+ napwid=50
if(ncontest.le.5 .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
diff --git a/lib/ft8/foxgen.f90 b/lib/ft8/foxgen.f90 index a2899e52..b9e39f62 100755 --- a/lib/ft8/foxgen.f90 +++ b/lib/ft8/foxgen.f90 @@ -1,4 +1,4 @@ -subroutine foxgen()
+subroutine foxgen(bSuperFox,fname)
! Called from MainWindow::foxTxSequencer() to generate the Tx waveform in
! FT8 Fox mode. The Tx message can contain up to 5 "slots", each carrying
@@ -17,7 +17,10 @@ subroutine foxgen() parameter (NN=79,ND=58,NSPS=4*1920)
parameter (NWAVE=(160+2)*134400*4) !the biggest waveform we generate (FST4-1800 at 48kHz)
parameter (NFFT=614400,NH=NFFT/2)
- character*40 cmsg
+ logical*1 bSuperFox,bMoreCQs,bSendMsg
+ character*(*) fname
+ character*40 cmsg,cmsg2
+ character*26 textMsg
character*37 msg,msgsent
integer itone(79)
integer*1 msgbits(77),msgbits2
@@ -25,10 +28,26 @@ subroutine foxgen() real x(NFFT)
real*8 dt,twopi,f0,fstep,dfreq,phi,dphi
complex cx(0:NH)
- common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall(12)
+ common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall(12), &
+ textMsg,bMoreCQs,bSendMsg
common/foxcom2/itone2(NN),msgbits2(77)
+ common/foxcom3/nslots2,cmsg2(5),itone3(151)
equivalence (x,cx),(y,cy)
+ if(bSuperFox) then
+ n=nslots
+ if(bMoreCQs) cmsg(1)(40:40)='1' !Set flag to include a CQ
+ if(bSendMsg) then
+ n=min(nslots+1,3)
+ cmsg(n)=textMsg
+ cmsg(n)(39:39)='1' !Set flag for text message
+ nslots=n
+ endif
+ nslots2=nslots
+ cmsg2=cmsg
+ go to 999
+ endif
+
fstep=60.d0
dfreq=6.25d0
dt=1.d0/48000.d0
@@ -66,7 +85,7 @@ subroutine foxgen() peak3=maxval(abs(wave))
wave=wave/peak3
- return
+999 return
end subroutine foxgen
! include 'plotspec.f90'
diff --git a/lib/ft8/foxgen_wrap.f90 b/lib/ft8/foxgen_wrap.f90 index 82510760..170b93fc 100755 --- a/lib/ft8/foxgen_wrap.f90 +++ b/lib/ft8/foxgen_wrap.f90 @@ -2,12 +2,12 @@ subroutine foxgen_wrap(msg40,msgbits,itone) parameter (NN=79,ND=58,KK=77,NSPS=4*1920)
parameter (NWAVE=(160+2)*134400*4) !the biggest waveform we generate (FST4-1800)
-
+ logical*1 bMoreCQs
character*40 msg40,cmsg
character*12 mycall12
integer*1 msgbits(KK),msgbits2
integer itone(NN)
- common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall12
+ common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall12,bMoreCQs
common/foxcom2/itone2(NN),msgbits2(KK)
nslots=1
diff --git a/lib/ft8/ft8_a7.f90 b/lib/ft8/ft8_a7.f90 index c7578edf..b77e641c 100755 --- a/lib/ft8/ft8_a7.f90 +++ b/lib/ft8/ft8_a7.f90 @@ -1,6 +1,6 @@ module ft8_a7
- parameter(MAXDEC=100)
+ parameter(MAXDEC=200)
! For the following three arrays
! First index i=decode number in this sequence
@@ -17,7 +17,7 @@ module ft8_a7 contains
-subroutine ft8_a7_save(nutc,dt,f,msg)
+subroutine ft8_a7_save(jseq,dt,f,msg)
use packjt77
character*37 msg,msg1
@@ -37,13 +37,12 @@ subroutine ft8_a7_save(nutc,dt,f,msg) call split77(msg,nwords,nw,w) !Parse msg into words
if(nwords.lt.1) go to 999
if(w(1)(1:3).eq.'CQ_') go to 999
- j=mod(nutc/5,2) !j is 0 or 1 for odd/even sequence
- jseq=j
+ j=jseq
! Add this decode to current table for this sequence
ndec(j,1)=ndec(j,1)+1 !Number of decodes in this sequence
i=ndec(j,1) !i is index of a new table entry
- if(i.ge.MAXDEC-1) return !Prevent table overflow
+ if(i.gt.MAXDEC) return !Prevent table overflow (indexes start at 1)
dt0(i,j,1)=dt !Save dt in table
f0(i,j,1)=f !Save f in table
@@ -362,9 +361,9 @@ subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, dmm(iloc(1))=1.e30
iloc=minloc(dmm)
dmin2=dmm(iloc(1))
- xsnr=-24.
+ xsnr=-25.
arg=pbest/xbase/3.0e6-1.0
- if(arg.gt.0.0) xsnr=max(-24.0,db(arg)-27.0)
+ if(arg.gt.0.0) xsnr=max(-25.0,db(arg)-27.0)
! write(41,3041) nharderrors,dmin,dmin2,dmin2/dmin,xsnr,trim(msgbest)
!3041 format(i3,2f7.1,f7.2,f7.1,1x,a)
if(dmin.gt.100.0 .or. dmin2/dmin.lt.1.3) nharderrors=-1
@@ -375,4 +374,48 @@ subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, return
end subroutine ft8_a7d
+subroutine getmsg(i,mycall,hiscall,hisgrid,msg)
+
+ character*12 mycall,hiscall
+ character*6 hisgrid
+ character*37 msg
+ logical my_std,his_std
+
+ call stdcall(mycall,my_std)
+ call stdcall(hiscall,his_std)
+
+ isnr=0
+ msg=trim(mycall)//' '//trim(hiscall)
+ if(.not.my_std) then
+ if(i.eq.1 .or. i.ge.6) msg='<'//trim(mycall)//'> '//trim(hiscall)
+ if(i.ge.2 .and. i.le.4) msg=trim(mycall)//' <'//trim(hiscall)//'>'
+ else if(.not.his_std) then
+ if(i.le.4 .or. i.eq.6) msg='<'//trim(mycall)//'> '//trim(hiscall)
+ if(i.ge.7) msg=trim(mycall)//' <'//trim(hiscall)//'>'
+ endif
+ j0=len(trim(msg))+2
+ if(i.eq.2) msg(j0:j0+2)='RRR'
+ if(i.eq.3) msg(j0:j0+3)='RR73'
+ if(i.eq.4) msg(j0:j0+1)='73'
+ if(i.eq.5) then
+ if(his_std) msg='CQ '//trim(hiscall)//' '//hisgrid(1:4)
+ if(.not.his_std) msg='CQ '//trim(hiscall)
+ endif
+ if(i.eq.6 .and. his_std) msg(j0:j0+3)=hisgrid(1:4)
+ if(i.ge.7 .and. i.le.206) then
+ isnr = -50 + (i-7)/2
+ if(iand(i,1).eq.1) then
+ write(msg(j0:j0+2),'(i3.2)') isnr
+ if(msg(j0:j0).eq.' ') msg(j0:j0)='+'
+ else
+ write(msg(j0:j0+3),'("R",i3.2)') isnr
+ if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+'
+ endif
+ endif
+
+ if(abs(isnr).gt.30) msg=''
+
+ return
+end subroutine getmsg
+
end module ft8_a7
diff --git a/lib/ft8/ft8_a8_test.f90 b/lib/ft8/ft8_a8_test.f90 new file mode 100755 index 00000000..02777460 --- /dev/null +++ b/lib/ft8/ft8_a8_test.f90 @@ -0,0 +1,47 @@ +program ft8_a8_test
+
+! Aid for testing "a8" decodes -- those based on known MyCall, DXcall, and DXgrid.
+
+ use wavhdr
+ use ft8_a7
+ include 'ft8_params.f90' !Set various constants
+ type(hdr) h !Header for .wav file
+ character arg*12,fname*120
+ character mycall*12,dxcall*12,dxgrid*6
+ character*37 msgbest
+ character*4 apflag
+ integer*2 iwave(NMAX) !Raw data from a *.wav file, fsample = 12000 Hz
+ real dd(NMAX) !Floating point copy of iwave
+
+! Get command-line argument(s)
+ nargs=iargc()
+ if(nargs.lt.6) then
+ print*,'Usage: ft8_a8_test MyCall DXcall DXgrid f1 ndepth fname [...]'
+ print*,'Example: ft8_a8_test W3SZ DL3WDG JN68 1500 3 250804_120500.wav'
+ go to 999
+ endif
+ call getarg(1,mycall) !Message to be transmitted
+ call getarg(2,dxcall)
+ call getarg(3,dxgrid)
+ call getarg(4,arg)
+ read(arg,*) f1 !Expected Rx Freq
+ call getarg(5,arg)
+ read(arg,*) ndepth !Decoding depth
+
+ do ifile=1,nargs-5
+ call getarg(ifile+5,fname) !File name for *.wav data
+ open(10,file=trim(fname),status='old',access='stream')
+ read(10) h,iwave
+ fac=1.0/32767.0
+ dd=fac*iwave
+
+ call ft8_a8d(dd,mycall,dxcall,dxgrid,f1,xdt,fbest,xsnr,plog,msgbest)
+
+ apflag=' a8'
+ if(plog.lt.-155) apflag(1:1)='?'
+ if(len(trim(msgbest)).eq.0) apflag=' '
+ write(*,1100) ifile,xdt,fbest,xsnr,plog,msgbest,apflag
+1100 format(i4,f6.2,3f7.1,1x,a37,a4)
+ enddo
+
+999 end program ft8_a8_test
diff --git a/lib/ft8/ft8_a8d.f90 b/lib/ft8/ft8_a8d.f90 new file mode 100755 index 00000000..508e5959 --- /dev/null +++ b/lib/ft8/ft8_a8d.f90 @@ -0,0 +1,187 @@ +subroutine ft8_a8d(dd,mycall,dxcall,dxgrid,f1a,xdt,fbest,xsnr,plog,msgbest)
+
+! List decoding for FT8, activated only at nfqso (Rx Freq) +/- 10 Hz and when
+! DxCall and DxGrid are populated. Returns xdt, fbest, and msgbest.
+
+ use packjt77
+ use ft8_a7
+ use timer_module, only: timer
+ include 'ft8_params.f90' !Set various constants
+ parameter (NWAVE=NN*NSPS/NDOWN) !Length of generated cwave = 2528
+ parameter (NZZ=3200) !Length of downsampled arrays
+ parameter (NFFT=NZZ,NH=NFFT/2) !FFT length
+ parameter (NMSGS=206) !Number of messages to be tried
+ parameter (PLOG_MIN=-160.0) !Minimum log probability
+ character mycall*12,dxcall*12,dxgrid*6
+ character*37 msg,msgsent,msgbest
+ character*77 c77
+ integer*1 msgbits(77)
+ real xjunk(NZZ)
+ real s(-NH:NH) !Power spectrum of cd0
+! real s00(-NH:NH) !Raw spectrum of downsampled data
+ real s0(-NH:NH) !Best-fit re-centered spectrum for this msg
+ real s1(-NH:NH) !Overall best-fit re-centered spectrum
+ real s8(0:7) !Spectrum of a single symbol
+ real dd(NMAX) !Floating point copy of iwave
+ real a(5)
+ complex cwave(0:NZZ-1) !Complex waveform corresponding to msg
+ complex cd(0:NZZ-1) !Data from dd, now complex and sampled at 200 Hz
+ complex cd0(0:NZZ-1) !All tones in cd nominally shifted to 0 Hz
+ complex csymb(0:31)
+ integer itone(NN)
+ integer itone_best(NN)
+ integer ipk(1)
+ logical newdat
+
+ f1=f1a
+ newdat=.true.
+! Mix from f1 to baseband and downsample from dd into cd (complex, 200 Hz sampling)
+ call ft8_downsample(dd,newdat,f1,cd)
+ fac=1.e-6
+
+ fsd=200.0 !Downsampled rate (Hz)
+ bt=2.0 !Gaussian smoothing parameter
+ dt=1.0/fsd
+ df=200.0/NFFT
+ s=0.
+ ss=0.
+ sq=0.
+
+! Find the message that fits the received waveform best
+ sbest=0.
+ tbest=0.
+ fbest=0.
+ msgbest=''
+ itone_best=0
+ do imsg=1,NMSGS
+ call getmsg(imsg,mycall,dxcall,dxgrid,msg)
+
+! Source-encode the message, get itone(), and generate complex FT8 waveform.
+ i3=-1
+ n3=-1
+ call pack77(msg,i3,n3,c77)
+ call genft8(msg,i3,n3,msgsent,msgbits,itone)
+ call gen_ft8wave(itone,NN,32,bt,fsd,0.0,cwave,xjunk,1,NWAVE)
+ cwave(NWAVE:)=0.
+
+! For this message, find the best lag
+ spk=0.
+ fpk=0.
+ tpk=0.
+ lagpk=0
+ lag1=-200
+ lag2=200
+ lagstep=4
+ do iter=1,2
+ if(iter.eq.2) then
+ lag1=lagpk-8
+ lag2=lagpk+8
+ lagstep=1
+ endif
+ do lag=lag1,lag2,lagstep
+ do i=0,NWAVE-1
+ j=i+lag + 100
+ cd0(i)=0.
+ if(j.ge.0 .and. j.le.NWAVE-1) cd0(i)=cd(j)*conjg(cwave(i))
+ enddo
+
+ cd0(NWAVE:)=0.
+ call four2a(cd0,NFFT,1,-1,1) !Forward c2c FFT
+
+ do i=0,NFFT-1
+ j=i
+ if(i.gt.NH) j=i-NFFT
+ s(j)=fac*(real(cd0(i))**2 + aimag(cd0(i))**2)
+ enddo
+
+ call smo121(s,NFFT+1)
+
+ smax=0.
+ do j=-NH,NH
+ smax=max(s(j),smax)
+ if(s(j).gt.spk) then
+ spk=s(j)
+ fpk=j*df + f1
+ lagpk=lag
+ tpk=lag*dt
+ s0=s !Save best-fit spectrum for this msg
+ endif
+ enddo ! j
+ enddo ! lag
+ enddo ! iter
+
+ if(spk.gt.sbest) then
+ sbest=spk
+ fbest=fpk
+ tbest=tpk
+ msgbest=msg
+ itone_best=itone
+ s1=s0 !Save overall best-fit spectrum
+ endif
+ enddo ! imsg
+
+ a=0
+ a(1)=f1-fbest
+! if(abs(a(1)+5.0).gt.10.0) then !Effective Ftol = 10 Hz
+ if(abs(a(1)).gt.5.0) then !Effective Ftol = 5 Hz
+ msgbest=''
+ return
+ endif
+ call twkfreq1(cd,NZZ,200.0,a,cd) !Re-center the spectrum
+
+ xdt=tbest
+ ave=(sum(s1(-200:-100)) + sum(s1(100:200)))/202.0
+ s1=s1/ave - 1.0
+ s1pk=maxval(s1(-32:32))
+ sig=0.
+ nsig=0
+ do i=-32,32
+ if(s1(i).lt.0.5*s1pk) cycle
+ sig=sig+s1(i)
+ nsig=nsig+1
+ enddo
+ sig=sig/nsig
+ xsnr=db(sig)-35.0
+
+ if(msgbest.ne.'') then
+! Compute probability of successful decode.
+ plog=0.0
+ nhard=0
+ nsum=0
+ sum_sync=0.
+ sum_sig=0.
+ sum_big=0.
+ do k=1,NN
+ i0=32*(k-1) + nint((tbest+0.5)/0.005)
+ csymb=0.
+ do i=0,31
+ if(i0+i.ge.0 .and. i0+i.le.NZZ-1) csymb(i)=cd(i0+i)
+ enddo
+ call four2a(csymb,32,1,-1,1) !c2c
+ do i=0,7
+ s8(i)=real(csymb(i))**2 + aimag(csymb(i))**2
+ enddo
+ s8sum=sum(s8)
+ if(s8sum.gt.0.0) then
+ p=s8(itone_best(k))/s8sum
+ plog=plog + log(p)
+ nsum=nsum+1
+ endif
+ ipk=maxloc(s8)-1
+ if(ipk(1).ne.itone_best(k)) nhard=nhard+1
+ if(k.le.7 .or. (k.ge.37 .and. k.le.43) .or. k.ge.73) then
+ sum_sync=sum_sync + s8(itone_best(k))
+ else
+ sum_sig=sum_sig + s8(itone_best(k))
+ endif
+ sum_big=sum_big + s8(ipk(1))
+ enddo
+ if(nsum.lt.NN) plog=plog + (NN-nsum)*log(0.125)
+ sigobig=(sum_sync+sum_sig)/sum_big
+! write(60,3060) nsum,xdt,fbest,xsnr,plog,nhard,sigosync,sigobig,trim(msgbest)
+!3060 format(i2,f8.3,3f8.1,i5,2f7.2,1x,a)
+ if(nhard.gt.54 .or. plog.lt.-159.0 .or. sigobig.lt.0.71) msgbest=''
+ endif
+
+ return
+end subroutine ft8_a8d
diff --git a/lib/ft8/ft8_downsample.f90 b/lib/ft8/ft8_downsample.f90 index f3552258..a57b5324 100755 --- a/lib/ft8/ft8_downsample.f90 +++ b/lib/ft8/ft8_downsample.f90 @@ -8,10 +8,10 @@ subroutine ft8_downsample(dd,newdat,f0,c1) logical newdat,first
complex c1(0:NFFT2-1)
complex cx(0:NFFT1/2)
- real dd(NMAX),x(NFFT1),taper(0:100)
- equivalence (x,cx)
+ real dd(NMAX),x(NFFT1+2),taper(0:100)
data first/.true./
- save cx,first,taper
+ save x,cx,first,taper
+ equivalence (x,cx)
if(first) then
pi=4.0*atan(1.0)
@@ -23,11 +23,10 @@ subroutine ft8_downsample(dd,newdat,f0,c1) if(newdat) then
! Data in dd have changed, recompute the long FFT
x(1:NMAX)=dd
- x(NMAX+1:NFFT1)=0. !Zero-pad the x array
+ x(NMAX+1:NFFT1+2)=0. !Zero-pad the x array
call four2a(cx,NFFT1,1,-1,0) !r2c FFT to freq domain
newdat=.false.
endif
-
df=12000.0/NFFT1
baud=12000.0/NSPS
i0=nint(f0/df)
diff --git a/lib/ft8/ft8_testmsg.f90 b/lib/ft8/ft8_testmsg.f90 index 931df4f5..1728e39f 100755 --- a/lib/ft8/ft8_testmsg.f90 +++ b/lib/ft8/ft8_testmsg.f90 @@ -1,10 +1,8 @@ - parameter (MAXTEST=75,NTEST=48)
+ parameter (MAXTEST=75,NTEST=49)
character*37 testmsg(MAXTEST)
data testmsg(1:NTEST)/ &
"TNX BOB 73 GL", & ! 0.0
"K1ABC RR73; W9XYZ <KH1/KH7Z> -08", & ! 0.1
- "PA9XYZ 590003 IO91NP", & ! 0.2
- "G4ABC/P R 570007 JO22DB", & ! 0.2
"K1ABC W9XYZ 6A WI", & ! 0.3
"W9XYZ K1ABC R 17B EMA", & ! 0.3
"123456789ABCDEF012", & ! 0.5
@@ -31,6 +29,9 @@ "<YW18FIFA> KA1ABC R-17", & ! 1.
"<YW18FIFA> KA1ABC 73", & ! 1.
"CQ G4ABC/P IO91", & ! 2.
+ "CQ TEST G4ABC/P IO91", & ! 2.
+ "<PA9XYZ> <G4ABC/P> 570123 IO91NP", & ! 2.
+ "<G4ABC/P> <PA9XYZ> R 580071 JO22DB", & ! 2.
"G4ABC/P PA9XYZ JO22", & ! 2.
"PA9XYZ G4ABC/P RR73", & ! 2.
"K1ABC W9XYZ 579 WI", & ! 3.
diff --git a/lib/ft8/ft8b.f90 b/lib/ft8/ft8b.f90 index 75b17adf..94423fff 100755 --- a/lib/ft8/ft8b.f90 +++ b/lib/ft8/ft8b.f90 @@ -1,5 +1,5 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, &
- lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, &
+ lapcqonly,napwid,lsubtract,nagain,ncontest,imetric,iaptype,mycall12,hiscall12, &
f1,xdt,xbase,apsym,aph10,nharderrors,dmin,nbadcrc,ipass, &
msg37,xsnr,itone)
@@ -14,10 +14,11 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & real a(5)
real s8(0:7,NN)
real s2(0:511)
- real bmeta(174),bmetb(174),bmetc(174),bmetd(174)
- real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols
+ real bmeta(174),bmetb(174),bmetc(174),bmetd(174),bmete(174)
+ real llra(174),llrb(174),llrc(174),llrd(174),llre(174),llrz(174) !Soft symbols
real dd0(15*12000)
real ss(9)
+ real temp(3)
integer*1 message77(77),message91(91),apmask(174),cw(174)
integer apsym(58),aph10(10)
integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29)
@@ -174,7 +175,10 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & enddo
! hard sync sum - max is 21
nsync=is1+is2+is3
- if(nsync .le. 6) then ! bail out
+ syncmin=6
+ if(imetric.eq.2) syncmin=7
+ if(ndepth.le.2) syncmin=8
+ if(nsync.le.syncmin) then ! bail out
nbadcrc=1
return
endif
@@ -200,6 +204,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & print*,"Error - nsym must be 1, 2, or 3."
endif
enddo
+ if(imetric.eq.2) s2=s2**2
i32=1+(k-1)*3+(ihalf-1)*87
if(nsym.eq.1) ibmax=2
if(nsym.eq.2) ibmax=5
@@ -227,18 +232,26 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & enddo
enddo
enddo
+ do i=1,174
+ temp(1)=bmeta(i)
+ temp(2)=bmetb(i)
+ temp(3)=bmetc(i)
+ ip=maxloc(abs(temp))
+ bmete(i)=temp(ip(1))
+ enddo
+
call normalizebmet(bmeta,174)
call normalizebmet(bmetb,174)
call normalizebmet(bmetc,174)
call normalizebmet(bmetd,174)
+ call normalizebmet(bmete,174)
scalefac=2.83
llra=scalefac*bmeta
llrb=scalefac*bmetb
llrc=scalefac*bmetc
llrd=scalefac*bmetd
-
- apmag=maxval(abs(llra))*1.01
+ llre=scalefac*bmete
! pass #
!------------------------------
@@ -246,35 +259,44 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & ! 2 regular decoding, nsym=2
! 3 regular decoding, nsym=3
! 4 regular decoding, nsym=1, bit-by-bit normalized
-! 5 ap pass 1, nsym=1
-! 6 ap pass 2
-! 7 ap pass 3
-! 8 ap pass 4
+! 5 regular decoding, choose best (largest) metric from 1-3
+! 6 ap pass 1, nsym=1
+! 7 ap pass 1, nsym=2
+! 8 ap pass 2, nsym=1
+! 9 ap pass 2, nsym=2
+! 10 ap pass 3, nsym=1
+! 11 ap pass 3, nsym=2
+! 12 ap pass 4, nsym=1
+! 13 ap pass 4, nsym=2
if(lapon.or.ncontest.eq.7) then !Hounds always use AP
if(.not.lapcqonly) then
- npasses=4+nappasses(nQSOProgress)
+ npasses=5+2*nappasses(nQSOProgress)
else
- npasses=5
+ npasses=7
endif
else
- npasses=4
+ npasses=5
endif
- if(nzhsym.lt.50) npasses=4
+ if(nzhsym.lt.50) npasses=5
do ipass=1,npasses
llrz=llra
if(ipass.eq.2) llrz=llrb
if(ipass.eq.3) llrz=llrc
if(ipass.eq.4) llrz=llrd
- if(ipass.le.4) then
+ if(ipass.eq.5) llrz=llre
+ if(ipass.le.5) then
apmask=0
iaptype=0
endif
- if(ipass .gt. 4) then
+ if(ipass .gt. 5) then
llrz=llra
+ if(mod(ipass-5,2).eq.1) llrz=llra
+ if(mod(ipass-5,2).eq.0) llrz=llrc
+ apmag=maxval(abs(llrz))*1.1
if(.not.lapcqonly) then
- iaptype=naptypes(nQSOProgress,ipass-4)
+ iaptype=naptypes(nQSOProgress,(ipass-4)/2)
else
iaptype=1
endif
@@ -405,7 +427,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & norder=2
maxosd=2
if(ndepth.eq.1) maxosd=-1 ! BP only
- if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD
+! if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD
if(ndepth.eq.3 .and. &
(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7)) then
maxosd=2
@@ -427,8 +449,13 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle
if(i3.eq.0 .and. n3.eq.2) cycle
call unpack77(c77,1,msg37,unpk77_success)
+ if(.not.unpk77_success .or. index(msg37,'/R').gt.0 .or. &
+ msg37(1:4).eq.'TU; ') then
+ if(i3.ge.1 .and. i3.le.3 .and. ncontest.eq.0) cycle
+ endif
if(.not.unpk77_success) cycle
- nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message.
+! If we get this far: valid codeword, valid (i3,n3), nonquirky message.
+ nbadcrc=0
call get_ft8_tones_from_77bits(message77,itone)
if(lsubtract) then
call timer('sub_ft8a',0)
@@ -453,11 +480,11 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & if(.not.nagain) then
xsnr=xsnr2
endif
- if(nsync.le.10 .and. xsnr.lt.-24.0) then !bail out, likely false decode
+ if(nsync.le.10 .and. xsnr.lt.-25.0) then !bail out, likely false decode
nbadcrc=1
return
endif
- if(xsnr .lt. -24.0) xsnr=-24.0
+ if(xsnr .lt. -25.0) xsnr=-25.0
return
enddo
return
diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90 index a7ff5793..45b0b6a6 100755 --- a/lib/ft8/ft8code.f90 +++ b/lib/ft8/ft8code.f90 @@ -23,9 +23,9 @@ program ft8code 'LDPC(174,91) encoding,'
print*,'bit and symbol ordering, and other details of the FT8 protocol.'
print*
- print*,'Usage: ft8code [-c grid] "message" # Results for specified message'
- print*,' ft8code -T # Examples of all message types'
- print*,' ft8code -t # Short format examples'
+ print*,'Usage: ft8code "message" # Results for specified message'
+ print*,' ft8code -T # Examples of all message types'
+ print*,' ft8code -t # Short format examples'
go to 999
endif
diff --git a/lib/ft8/ft8d.f90 b/lib/ft8/ft8d.f90 index b7b39fc7..28af93d1 100755 --- a/lib/ft8/ft8d.f90 +++ b/lib/ft8/ft8d.f90 @@ -42,7 +42,7 @@ program ft8d j2=index(infile,'.wav')
read(infile(j2-6:j2-1),*) nutc
datetime=infile(j2-13:j2-1)
- call sync8(iwave,nfa,nfb,nfqso,s,candidate,ncand)
+ call sync8(iwave,NMAX,nfa,nfb,nfqso,s,candidate,ncand)
syncmin=2.0
dd=iwave
do icand=1,ncand
diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90 index a12b6d60..92ee51d9 100755 --- a/lib/ft8/ft8sim.f90 +++ b/lib/ft8/ft8sim.f90 @@ -24,7 +24,8 @@ program ft8sim_gfsk nargs=iargc()
if(nargs.ne.7) then
print*,'Usage: ft8sim "message" f0 DT fdop del nfiles snr'
- print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 10 -18'
+ print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.5 1.0 10 -18'
+ print*,' ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 MM 1.0 10 -18'
print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 10 -18'
print*,' ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10'
print*,' ft8sim "<G4ABC/P> <PA9XYZ> R 570007 JO22DB" 1500 0 0 0 1 -10'
@@ -36,9 +37,38 @@ program ft8sim_gfsk call getarg(3,arg)
read(arg,*) xdt !Time offset from nominal (s)
call getarg(4,arg)
- read(arg,*) fspread !Watterson frequency spread (Hz)
- call getarg(5,arg)
- read(arg,*) delay !Watterson delay (ms)
+ if(arg(1:2).eq.'LQ') then !ITU params for Low Latitude Quiet
+ fspread=0.5
+ delay=0.5
+ else if(arg(1:2).eq.'LM') then !Low Latitude Moderate
+ fspread=1.5
+ delay=2.0
+ else if(arg(1:2).eq.'LD') then !Low Latitude Disturbed
+ fspread=10.0
+ delay=6.0
+ else if(arg(1:2).eq.'MQ') then !Mid Latitude ... etc.
+ fspread=0.1
+ delay=0.5
+ else if(arg(1:2).eq.'MM') then
+ fspread=0.5
+ delay=1.0
+ else if(arg(1:2).eq.'MD') then
+ fspread=1.0
+ delay=2.0
+ else if(arg(1:2).eq.'HQ') then
+ fspread=0.5
+ delay=1.0
+ else if(arg(1:2).eq.'HM') then
+ fspread=10.0
+ delay=3.0
+ else if(arg(1:2).eq.'HD') then
+ fspread=30.0
+ delay=7.0
+ else
+ read(arg,*) fspread !Watterson frequency spread (Hz)
+ call getarg(5,arg)
+ read(arg,*) delay !Watterson delay (ms)
+ endif
call getarg(6,arg)
read(arg,*) nfiles !Number of files
call getarg(7,arg)
@@ -72,10 +102,12 @@ program ft8sim_gfsk call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) !Generate complex cwave
write(*,*)
- write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3
+ write(*,'(a,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3
write(*,1000) f0,xdt,txt,snrdb,bw
-1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, &
- ' BW:',f4.1)
+1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1,' BW:',f4.1)
+ write(*,1001) fspread,delay
+1001 format('Fspread:',f7.3,' Hz Delay:',f7.3,' ms')
+
write(*,*)
if(i3.eq.1) then
write(*,*) ' mycall hiscall hisgrid'
@@ -101,14 +133,24 @@ program ft8sim_gfsk wave=imag(c)
peak=maxval(abs(wave))
nslots=1
-
+
+ psig=0.
+ pnoise=0.
if(snrdb.lt.90) then
do i=1,NMAX !Add gaussian noise at specified SNR
xnoise=gran()
+ if(i.ge.6001 .and. i.le.157692) then
+ psig=psig + wave(i)*wave(i) !Signal power
+ pnoise=pnoise + xnoise*xnoise !Noise power in signal interval
+ endif
wave(i)=wave(i) + xnoise
enddo
endif
+! Noise power in signal interval and 2500 Hz bandwidth:
+ pnoise=bandwidth_ratio*pnoise
+ snr_2500=db(psig/pnoise) !SNR in 2500 Hz bandwidth
+
gain=100.0
if(snrdb.lt.90.0) then
wave=gain*wave
@@ -125,7 +167,7 @@ program ft8sim_gfsk open(10,file=fname,status='unknown',access='stream')
write(10) h,iwave !Save to *.wav file
close(10)
- write(*,1110) ifile,xdt,f0,snrdb,fname
-1110 format(i4,f7.2,f8.2,f7.1,2x,a17)
+ write(*,1110) ifile,xdt,f0,snrdb,fname,snr_2500
+1110 format(i4,f7.2,f8.2,f7.1,2x,a17,f8.2)
enddo
999 end program ft8sim_gfsk
diff --git a/lib/ft8/gen_ft8wave.f90 b/lib/ft8/gen_ft8wave.f90 index 1d395520..ba9fbb4e 100755 --- a/lib/ft8/gen_ft8wave.f90 +++ b/lib/ft8/gen_ft8wave.f90 @@ -49,7 +49,6 @@ subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) if(icmplx .eq. 0) wave=0.
if(icmplx .ne. 0) cwave=0. !Avoid writing to memory we may not have access to
- call timer('gen_loop',0)
k=0
do j=nsps,nsps+nwave-1 !Don't include dummy symbols
k=k+1
@@ -61,7 +60,6 @@ subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) endif
phi=mod(phi+dphi(j),twopi)
enddo
- call timer('gen_loop',1)
! Apply envelope shaping to the first and last symbols
nramp=nint(nsps/8.0)
diff --git a/lib/ft8/ldpcsim174_91.f90 b/lib/ft8/ldpcsim174_91.f90 index fc2074f6..ae16fa43 100755 --- a/lib/ft8/ldpcsim174_91.f90 +++ b/lib/ft8/ldpcsim174_91.f90 @@ -2,38 +2,50 @@ program ldpcsim174_91 ! End to end test of the (174,91)/crc14 encoder and decoder.
use packjt77
- integer, parameter:: N=174, K=91, M=N-K
- character*37 msg,msgsent,msgreceived
+ integer, parameter:: N=174, K=91, M=N-K, NN=58
+ character*37 msg,msgsent
character*77 c77
character*8 arg
- character*6 grid
- character*96 tmpchar
integer*1, allocatable :: codeword(:), decoded(:), message(:)
integer*1 msgbits(77)
- integer*1 message77(77),message91(91)
+ integer*1 message91(91)
integer*1 apmask(N), cw(N)
+ integer lmax(1)
+ integer modtype, itone(79), itonecw(58), graymap(0:7)
integer nerrtot(0:N),nerrdec(0:N)
+ integer channeltype
logical unpk77_success
+ logical one(0:511,0:8)
real*8, allocatable :: rxdata(:)
- real, allocatable :: llr(:)
+ real llr(174),llra(174),llrb(174),llrc(174),llrd(174)
+ real bmeta(174),bmetb(174),bmetc(174),bmetd(174)
+ complex cs(0:7,NN)
+ real s2(0:511)
+ data graymap/0,1,3,2,5,6,4,7/
nerrtot=0
nerrdec=0
+!
+
nargs=iargc()
- if(nargs.ne.6) then
- print*,'Usage: ldpcsim niter ndepth #trials s Keff nbposd'
- print*,'eg: ldpcsim 10 2 1000 0.84 91 1'
- print*,'niter: max BP iterations'
- print*,'ndepth: OSD order'
- print*,'s: noise sigma; if negative value is ignored and sigma is calculated from SNR.'
- print*,'nbposd=0, no coupling. nbposd>0, maxsuper=nbposd; nbposd<0, no OSD'
+ if(nargs.ne.7) then
+ print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel'
+ print*,'eg: ldpcsim 10 2 1000 0.84 91 1 0'
+ print*,' maxosd<0: do bp only'
+ print*,' maxosd=0: do bp and then call osd once with channel llrs'
+ print*,' maxosd>1: do bp and then call osd maxosd times with saved bp outputs'
+ print*,' norder : osd decoding depth'
+ print*,' s : BPSK only, noise sigma, if s<0 value is ignored and sigma is calculated from SNR.'
+ print*,' Keff : Keff must be in the range [77,91]; Keff-77 is the # of bits to use as CRC.'
+ print*,' modtype : 0, coherent BPSK; 1 noncoherent 8FSK'
+ print*,' channel : 0, AWGN; 1, block Rayleigh (Rayleigh only works with 8FSK!)'
return
endif
call getarg(1,arg)
- read(arg,*) max_iterations
+ read(arg,*) maxosd
call getarg(2,arg)
- read(arg,*) ndepth
+ read(arg,*) norder
call getarg(3,arg)
read(arg,*) ntrials
call getarg(4,arg)
@@ -41,16 +53,24 @@ program ldpcsim174_91 call getarg(5,arg)
read(arg,*) Keff
call getarg(6,arg)
- read(arg,*) nbposd
+ read(arg,*) modtype
+ call getarg(7,arg)
+ read(arg,*) channeltype
! scale Eb/No for a (174,91) code
rate=real(K)/real(N)
write(*,*) "rate: ",rate
- write(*,*) "niter= ",max_iterations," s= ",s
allocate ( codeword(N), decoded(K), message(K) )
- allocate ( rxdata(N), llr(N) )
+ allocate ( rxdata(N) )
+
+ one=.false.
+ do i=0,511
+ do j=0,8
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
msg="K9ABC K1ABC FN20"
i3=0
@@ -65,47 +85,144 @@ program ldpcsim174_91 call init_random_seed()
+ iq=1
+ if(modtype.gt.0) then ! MFSK - get tones
+ i3=-1
+ n3=-1
+ call genft8(msg,i3,n3,msgsent,msgbits,itone)
+ write(*,*) 'message tones'
+ write(*,'(79(i1,1x))') itone
+ itonecw(1:29)=itone(8:36)
+ itonecw(30:58)=itone(44:72)
+ iq=3 ! bits per symbol
+ endif
call encode174_91(msgbits,codeword)
write(*,*) 'crc14'
write(*,'(14i1)') codeword(78:91)
write(*,*) 'codeword'
write(*,'(22(8i1,1x))') codeword
-
- write(*,*) "Eb/N0 Es/N0 ngood nundetected sigma psymerr"
- do idb = 10,-4,-1
+ write(*,*) 'Eb/N0 Es/N0 SNR2500 ngood nundetected sigma psymerr pbiterr'
+ do idb = 20,-4,-1
+ nsymerr=0
+ nbiterr=0
db=idb/2.0-1.0
- sigma=1/sqrt( 2*rate*(10**(db/10.0)) )
+ sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) )
ngood=0
nue=0
nsumerr=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
- if(nerr.ge.1) nerrtot(nerr)=nerrtot(nerr)+1
-
- rxav=sum(rxdata)/N
- rx2av=sum(rxdata*rxdata)/N
- rxsig=sqrt(rx2av-rxav*rxav)
- rxdata=rxdata/rxsig
- if( s .lt. 0 ) then
- ss=sigma
+ if(modtype.eq.0) then
+ 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
+ if(nerr.ge.1) nerrtot(nerr)=nerrtot(nerr)+1
+
+ 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)
else
- ss=s
+! noncoherent MFSK
+ do i=1,58
+ do j=0,7
+ if(j.eq.itonecw(i)) then
+ if(channeltype.eq.0) then
+ A=1.0
+ elseif(channeltype.eq.1) then
+ xI=gran()**2 + gran()**2
+ A=sqrt(xI/2)
+ endif
+ cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran()
+ elseif(j.ne.itonecw(i)) then
+ cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran()
+ endif
+ enddo
+ lmax=maxloc(abs(cs(:,i)))
+ if(lmax(1)-1.ne.itonecw(i) ) nsymerr=nsymerr+1
+ enddo
+ do nsym=1,3
+ nt=2**(3*nsym)
+ do ks=1,58,nsym
+ amax=-1.0
+ do i=0,nt-1
+ i1=i/64
+ i2=iand(i,63)/8
+ i3=iand(i,7)
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i3),ks))
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1))
+ elseif(nsym.eq.3) then
+ if(ks.ne.58) then
+ s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2))
+ else
+ s2(i)=abs(cs(graymap(i1),ks))
+ endif
+ else
+ print*,"Error - nsym must be 1, 2, or 3."
+ endif
+ enddo
+
+ i32=1+(ks-1)*3
+ if(nsym.eq.1) ibmax=2
+ if(nsym.eq.2) ibmax=5
+ if(nsym.eq.3) ibmax=8
+ 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(i32+ib .gt.174) cycle
+ if(nsym.eq.1) then
+ bmeta(i32+ib)=bm
+ den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), &
+ maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)))
+ if(den.gt.0.0) then
+ cm=bm/den
+ else ! erase it
+ cm=0.0
+ endif
+ bmetd(i32+ib)=cm
+ elseif(nsym.eq.2) then
+ bmetb(i32+ib)=bm
+ elseif(nsym.eq.3) then
+ bmetc(i32+ib)=bm
+ endif
+ enddo
+ enddo
+ enddo
+ call normalizebmet(bmeta,174)
+ call normalizebmet(bmetb,174)
+ call normalizebmet(bmetc,174)
+ call normalizebmet(bmetd,174)
+
+ scalefac=2.83
+ llra=scalefac*bmeta
+ llrb=scalefac*bmetb
+ llrc=scalefac*bmetc
+ llrd=scalefac*bmetd
+
+ llr=llrc
endif
- llr=2.0*rxdata/(ss*ss)
+ do i=1, 174
+ if(llr(i)*(codeword(i)-0.5).lt.0) nbiterr=nbiterr+1
+ enddo
+
nap=0 ! number of AP bits
llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0)
apmask=0
apmask(1:nap)=1
- call decode174_91(llr,Keff,nbposd,ndepth,apmask,message91,cw,ntype,nharderrors,dmin)
+ call decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderrors,dmin)
! If the decoder finds a valid codeword, nharderrors will be .ge. 0.
if( nharderrors.ge.0 ) then
nhw=count(cw.ne.codeword)
@@ -119,9 +236,12 @@ program ldpcsim174_91 nsumerr=nsumerr+nerr
enddo
- esn0=db+10.0*log10(rate)
- pberr=real(nsumerr)/(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
+ esn0=db+10.0*log10(iq*rate) ! iq=3 bits per symbol for 8FSK
+ snr2500=esn0-10.0*log10(2500/6.25)
+! pberr=real(nsumerr)/(real(ntrials*N))
+ psymerr=real(nsymerr)/(ntrials*174.0/iq)
+ pbiterr=real(nbiterr)/(ntrials*174.0)
+ write(*,"(f4.1,4x,f5.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3,8x,e10.3)") db,esn0,snr2500,ngood,nue,ss,psymerr,pbiterr
enddo
@@ -132,3 +252,18 @@ program ldpcsim174_91 close(23)
end program ldpcsim174_91
+
+subroutine normalizebmet(bmet,n)
+ real bmet(n)
+
+ bmetav=sum(bmet)/real(n)
+ bmet2av=sum(bmet*bmet)/real(n)
+ var=bmet2av-bmetav*bmetav
+ if( var .gt. 0.0 ) then
+ bmetsig=sqrt(var)
+ else
+ bmetsig=sqrt(bmet2av)
+ endif
+ bmet=bmet/bmetsig
+ return
+end subroutine normalizebmet
diff --git a/lib/ft8/sync8.f90 b/lib/ft8/sync8.f90 index f93afe75..b79e416f 100755 --- a/lib/ft8/sync8.f90 +++ b/lib/ft8/sync8.f90 @@ -1,5 +1,4 @@ -subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,nzhsym,candidate, &
- ncand,sbase)
+subroutine sync8(dd,npts,nfa,nfb,syncmin,nfqso,maxcand,candidate,ncand,sbase)
include 'ft8_params.f90'
parameter (MAXPRECAND=1000)
@@ -10,13 +9,13 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,nzhsym,candidate, & real s(NH1,NHSYM)
real savg(NH1)
real sbase(NH1)
- real x(NFFT1)
+ real x(NFFT1+2)
real sync2d(NH1,-JZ:JZ)
real red(NH1)
real red2(NH1)
real candidate0(3,MAXPRECAND)
real candidate(3,maxcand)
- real dd(NMAX)
+ real dd(npts)
integer jpeak(NH1)
integer jpeak2(NH1)
integer indx(NH1)
@@ -87,7 +86,7 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,nzhsym,candidate, & red=0.
red2=0.
- mlag=10
+ mlag=13
mlag2=JZ
do i=ia,ib
ii=maxloc(sync2d(i,-mlag:mlag)) - 1 - mlag
diff --git a/lib/ft8/watterson.f90 b/lib/ft8/watterson.f90 index 7c3aa35d..6fd0edf8 100755 --- a/lib/ft8/watterson.f90 +++ b/lib/ft8/watterson.f90 @@ -24,7 +24,7 @@ subroutine watterson(c,npts,nsig,fs,delay,fspread) do i=0,npts-1
f=i*df
if(i.gt.npts/2) f=(i-npts)*df
- x=(f/(0.5*fspread))**2
+ x=(f/fspread)**2
a=0.
if(x.le.50.0) then
a=exp(-x)
diff --git a/lib/ft8_decode.f90 b/lib/ft8_decode.f90 index fdad82aa..24b8be94 100755 --- a/lib/ft8_decode.f90 +++ b/lib/ft8_decode.f90 @@ -34,7 +34,7 @@ contains subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat, &
nutc,nfa,nfb,nzhsym,ndepth,emedelay,ncontest,nagain,lft8apon, &
- lapcqonly,napwid,mycall12,hiscall12,ldiskdat)
+ ltry_a8,lapcqonly,napwid,mycall12,hiscall12,hisgrid,ldiskdat)
use iso_c_binding, only: c_bool, c_int
use timer_module, only: timer
use shmem, only: shmem_lock, shmem_unlock
@@ -44,50 +44,54 @@ contains class(ft8_decoder), intent(inout) :: this
procedure(ft8_decode_callback) :: callback
- parameter (MAXCAND=600,MAX_EARLY=100)
+ parameter (MAXCAND=1000,MAX_EARLY=200,NPTS=15*12000)
real*8 tsec,tseq
- real s(NH1,NHSYM)
real sbase(NH1)
real candidate(3,MAXCAND)
- real dd(15*12000),dd1(15*12000)
+ real dd(NPTS),dd1(NPTS)
logical, intent(in) :: lft8apon,lapcqonly,nagain
- logical newdat,lsubtract,ldupe,lrefinedt
+ logical newdat,lsubtract,ldupe,lrefinedt,ltry_a8
logical*1 ldiskdat
logical lsubtracted(MAX_EARLY)
+ logical la8
character*12 mycall12,hiscall12,call_1,call_2
+ character*6 hisgrid
character*4 grid4
- integer*2 iwave(15*12000)
+ integer*2 iwave(NPTS)
integer apsym2(58),aph10(10)
character datetime*13,msg37*37
- character*37 allmessages(200)
+ character*37 allmessages(MAX_EARLY)
character*12 ctime
- integer allsnrs(100)
+ integer allsnrs(MAX_EARLY)
integer itone(NN)
integer itone_save(NN,MAX_EARLY)
real f1_save(MAX_EARLY)
real xdt_save(MAX_EARLY)
data nutc0/-1/
- save s,dd,dd1,nutc0,ndec_early,itone_save,f1_save,xdt_save,lsubtracted,&
+ save dd,dd1,nutc0,ndec_early,itone_save,f1_save,xdt_save,lsubtracted, &
allmessages
-
this%callback => callback
write(datetime,1001) nutc !### TEMPORARY ###
1001 format("000000_",i6.6)
+ la8=.true.
+ if(nzhsym .eq. 41) jseq=mod(nutc/5,2)
if(nutc0.eq.-1) then
msg0=' '
dt0=0.
f0=0.
endif
-!Added 41==nzhsym to force a reset if the same wav file is processed twice or more in a row,
-!in which case nutc.eq.nutc0 and ndec(jseq,1) doesn't get reset
+
+! Added 41==nzhsym to force a reset if the same wav file is processed twice or
+! more in a row, in which case nutc.eq.nutc0 and ndec(jseq,1) doesn't get reset
if(nzhsym==41 .or. (nutc.ne.nutc0)) then
! New UTC. Move previously saved 'a7' data from k=1 to k=0
iz=ndec(jseq,1)
dt0(1:iz,jseq,0) = dt0(1:iz,jseq,1)
f0(1:iz,jseq,0) = f0(1:iz,jseq,1)
msg0(1:iz,jseq,0) = msg0(1:iz,jseq,1)
+
ndec(jseq,0)=iz
ndec(jseq,1)=0
nutc0=nutc
@@ -102,7 +106,6 @@ contains if(ndepth.eq.1 .and. nzhsym.eq.50) then
dd=iwave
endif
-
call ft8apset(mycall12,hiscall12,ncontest,apsym2,aph10)
if(nzhsym.le.47) then
@@ -171,30 +174,30 @@ contains ! ndepth=2: subtraction, 3 passes, bp+osd (no subtract refinement)
! ndepth=3: subtraction, 3 passes, bp+osd
npass=3
+ imetric=1
if(ndepth.eq.1) npass=2
do ipass=1,npass
newdat=.true.
syncmin=1.3
- if(ndepth.le.2) syncmin=1.6
- if(nzhsym.eq.41) syncmin=2.0
+ if(ndepth.le.2) syncmin=2.1
+! if(nzhsym.eq.41) syncmin=2.0
if(ipass.eq.1) then
lsubtract=.true.
- ndeep=ndepth
- if(ndepth.eq.3) ndeep=2
+ imetric=1
elseif(ipass.eq.2) then
n2=ndecodes
- if(ndecodes.eq.0) cycle
+ imetric=2
+! if(ndecodes.eq.0) imetric=2
lsubtract=.true.
- ndeep=ndepth
elseif(ipass.eq.3) then
- if((ndecodes-n2).eq.0) cycle
+ imetric=2
+! if((ndecodes-n2).eq.0) cycle
+ if(ndecodes.eq.0) cycle
lsubtract=.true.
- ndeep=ndepth
endif
call timer('sync8 ',0)
maxc=MAXCAND
- call sync8(dd,ifa,ifb,syncmin,nfqso,maxc,nzhsym,candidate, &
- ncand,sbase)
+ call sync8(dd,NPTS,ifa,ifb,syncmin,nfqso,maxc,candidate,ncand,sbase)
call timer('sync8 ',1)
do icand=1,ncand
sync=candidate(3,icand)
@@ -203,8 +206,8 @@ contains xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0))
msg37=' '
call timer('ft8b ',0)
- call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndeep,nzhsym,lft8apon, &
- lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12, &
+ call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lft8apon, &
+ lapcqonly,napwid,lsubtract,nagain,ncontest,imetric,iaptype,mycall12, &
hiscall12,f1,xdt,xbase,apsym2,aph10,nharderrors,dmin, &
nbadcrc,iappass,msg37,xsnr,itone)
call timer('ft8b ',1)
@@ -217,6 +220,9 @@ contains if(msg37.eq.allmessages(id)) ldupe=.true.
enddo
if(.not.ldupe) then
+ if(ndecodes.ge.MAX_EARLY) then
+ cycle
+ endif
ndecodes=ndecodes+1
allmessages(ndecodes)=msg37
allsnrs(ndecodes)=nsnr
@@ -228,7 +234,7 @@ contains qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0]
if(emedelay.ne.0) xdt=xdt+2.0
call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual)
- call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table
+ call ft8_a7_save(jseq,xdt,f1,msg37) !Enter decode in table
endif
endif
call timestamp(tsec,tseq,ctime)
@@ -241,7 +247,9 @@ contains if(nzhsym.lt.50) ndec_early=ndecodes
900 continue
- if(lft8apon .and. ncontest.ne.6 .and. ncontest.ne.7 .and. nzhsym.eq.50 .and. ndec(jseq,0).ge.1) then
+
+ if(lft8apon .and. ncontest.ne.6 .and. ncontest.ne.7 .and. nzhsym.eq.50 .and. &
+ ndec(jseq,0).ge.1) then
newdat=.true.
do i=1,ndec(jseq,0)
if(f0(i,jseq,0).eq.-99.0) exit
@@ -269,13 +277,36 @@ contains nsnr=xsnr
iaptype=7
qual=1.0
+ if(index(msg37,trim(hiscall12)).gt.0) la8=.false.
call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual)
- call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table
+ call ft8_a7_save(jseq,xdt,f1,msg37) !Enter decode in table
endif
endif
enddo
endif
+ if(lft8apon .and. ncontest.ne.6 .and. ncontest.ne.7 .and. nzhsym.eq.50 .and. &
+ la8 .and. len(trim(hiscall12)).ge.3 .and. len(trim(hisgrid)).ge.4 .and. &
+ ltry_a8) then
+! Try for an a8 decode at nfqso
+ f1=nfqso
+ call timer('ft8_a8d ',0)
+ call ft8_a8d(dd,mycall12,hiscall12,hisgrid,f1,xdt,fbest,xsnr,plog,msg37)
+ call timer('ft8_a8d ',1)
+
+ if(msg37(1:1).ne.' ') then
+ if(associated(this%callback)) then
+ sync=10.0 !### ???
+ nsnr=nint(xsnr)
+ iaptype=8
+ qual=1.0
+ if(plog.lt.-147.0) qual=0.16
+ call this%callback(sync,nsnr,xdt,fbest,msg37,iaptype,qual)
+ call ft8_a7_save(jseq,xdt,f1,msg37) !Enter decode in the a7 table
+ endif
+ endif
+ endif
+
return
end subroutine decode
diff --git a/lib/ft8var/agccft8.f90 b/lib/ft8var/agccft8.f90 new file mode 100755 index 00000000..749c2d15 --- /dev/null +++ b/lib/ft8var/agccft8.f90 @@ -0,0 +1,81 @@ +subroutine agccft8(nfa,nfb,forcedt)
+
+ use ft8_mod1, only : dd8,twopi,lagccbail
+ integer, parameter :: NFFT=1024,NSZ=426,NHSYM=178,NHSTEP=960 !3413 = NFFT*5000/12000
+ ! nhsym=(npts-NFFT)/nhstep !number of half-symbols 178.96(6) = (180000-8192)/(1920/2)
+ real*4 x11(NFFT),w11(NFFT),ss33(NSZ),s3(NHSYM)
+ real, DIMENSION(:), ALLOCATABLE :: sa33
+ integer, DIMENSION(:), ALLOCATABLE :: indx
+ integer, intent(in) :: nfa,nfb
+ complex c11(0:NFFT/2)
+ logical(1) first
+ equivalence (x11,c11)
+ data first/.true./
+ save first,w11
+
+ if(first) then ! FFT window
+ do k=1,NFFT
+ w11(k)=sin(twopi*(k+2)/2048) ! 16384 = 2*NFFT
+ enddo
+ first=.false.
+ endif
+
+ fac1=1.1e-3 ! 7548, 9.6e-4 7540, 9.7e-4 7546, 9.8e-4 7543, 1.0e-3 7539, 1.2e-3 7534..7538, 1.3e-3 7547, 2.4e-3 7543
+
+ if(nfb.lt.5000) then; nfblim=nfb; else; nfblim=4999; endif ! ss33 top index protection
+ nf1=NFFT*nfa/12000+1; nf2=NFFT*nfblim/12000
+ nmed=(nf2-nf1)/2; nsb=nf2-nf1+1
+
+ allocate(sa33(nsb), STAT = nAllocateStatus1)
+ if(nAllocateStatus1.ne.0) STOP "Not enough memory"
+ allocate(indx(nsb), STAT = nAllocateStatus1)
+ if(nAllocateStatus1.ne.0) STOP "Not enough memory"
+
+ do j=1,10
+ i0=(j-1)*nhstep; x11=fac1*w11*dd8(i0+1:i0+NFFT)
+ call four2avar(c11,NFFT,1,-1,0) !r2c forward FFT
+ do i=nf1,nf2
+ s33=ABS(c11(i)); ss33(i)=SQRT(s33)
+ enddo
+ sa33(1:nsb)=ss33(nf1:nf2)
+ call indexx(sa33(1:nsb),nsb,indx)
+ smed=sa33(indx(nmed)); if(smed.gt.1.e-6) then; s3(j)=smed; else; s3(j)=1.0; endif
+ enddo
+
+ do j=169,178
+ i0=(j-1)*nhstep; x11=fac1*w11*dd8(i0+1:i0+NFFT)
+ call four2avar(c11,NFFT,1,-1,0) !r2c forward FFT
+ do i=nf1,nf2
+ s33=ABS(c11(i)); ss33(i)=SQRT(s33)
+ enddo
+ sa33(1:nsb)=ss33(nf1:nf2)
+ call indexx(sa33(1:nsb),nsb,indx)
+ smed=sa33(indx(nmed)); if(smed.gt.1.e-6) then; s3(j)=smed; else; s3(j)=1.0; endif
+ enddo
+
+ deallocate (sa33, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ deallocate (indx, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+
+ s3min1=minval(s3(1:10)); s3min2=minval(s3(169:178)); s3min=min(s3min1,s3min2)
+ s3max1=maxval(s3(1:10)); s3max2=maxval(s3(169:178)); s3max=max(s3max1,s3max2)
+ if(s3min.lt.0.1) then; s3min=1.0; s3max=1.0; endif
+ s3ratio=s3max/s3min
+
+ lagccbail=.false.
+! 2.0dB delta
+ if(s3ratio.lt.1.26) then; lagccbail=.true.; return; endif
+
+ k=1
+ do j=1,10
+ dd8(k:k+959)=dd8(k:k+959)/s3(j); k=k+960
+ enddo
+ k=1+168*960
+ do j=169,178
+ dd8(k:k+959)=dd8(k:k+959)/s3(j); k=k+960
+ enddo
+ dd8(170881:171650)=dd8(170881:171650)/s3(178); dd8(171651:180000)=0.
+
+ return
+end subroutine agccft8
\ No newline at end of file diff --git a/lib/ft8var/baddatavar.f90 b/lib/ft8var/baddatavar.f90 new file mode 100755 index 00000000..77e5121a --- /dev/null +++ b/lib/ft8var/baddatavar.f90 @@ -0,0 +1,32 @@ +logical function baddatavar()
+
+ use jt65_mod6
+
+ ninterval=1200
+ j=0
+ smin=1.e30
+ smax=-smin
+ iz=49*12000/ninterval
+ nadd=ninterval/60
+
+ ! 3457-4800 range: cover broken data being observed under Windows XP
+ if(abs(dd(4200)).lt.0.1) dd(4200)=1.0
+
+ do i=1,iz
+ sq=0.
+ do n=1,ninterval,60
+ j=j+60
+ x=dd(j)
+ sq=sq + x*x
+ enddo
+ rms=sqrt(sq/nadd)
+ smin=min(smin,rms)
+ smax=max(smax,rms)
+ enddo
+
+ sratio=smax/(smin+1.e-30)
+ baddatavar=.false.
+ if(sratio.gt.1.e30) baddatavar=.true.
+
+ return
+end function baddatavar
diff --git a/lib/ft8var/bpdecode174_91var.f90 b/lib/ft8var/bpdecode174_91var.f90 new file mode 100755 index 00000000..999499f0 --- /dev/null +++ b/lib/ft8var/bpdecode174_91var.f90 @@ -0,0 +1,117 @@ +subroutine bpdecode174_91var(llr,apmask,maxiterations,message77,cw,nharderror,iter)
+!
+! A log-domain belief propagation decoder for the (174,91) code.
+!
+use iso_c_binding, only: c_loc,c_size_t
+use crc
+integer, parameter:: N=174, K=91, M=N-K
+integer*1 cw(N)
+integer*1, intent(in) :: apmask(N)
+integer*1 decoded(K)
+integer*1 message77(77)
+integer nrw(M),ncw
+integer Nm(7,M)
+integer Mn(3,N) ! 3 checks per bit
+integer synd(M)
+real tov(3,N)
+real toc(7,M)
+real tanhtoc(7,M)
+real zn(N)
+real, intent(in) :: llr(N)
+real Tmn
+
+include "ldpc_174_91_c_reordered_parity.f90"
+
+nclast=0
+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
+
+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
+! write(*,*) 'number of unsatisfied parity checks ',ncheck
+ if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it
+ decoded=cw(1:K)
+ call chkcrc14a(decoded,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:7,i)=tanh(-toc(1:7,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_91var
diff --git a/lib/ft8var/call_q.f90 b/lib/ft8var/call_q.f90 new file mode 100755 index 00000000..9cbad578 --- /dev/null +++ b/lib/ft8var/call_q.f90 @@ -0,0 +1,10 @@ +
+! call may not start from 'Q', zero and two digits
+ if(call_a(1:1).eq.'Q' .or. call_b(1:1).eq.'Q') then
+ nbadcrc=1; msg37=' '; return; endif
+ if(call_a(1:1).eq.'0' .or. call_b(1:1).eq.'0') then
+ nbadcrc=1; msg37=' '; return; endif
+ if(call_a(1:1).ge.'0' .and. call_a(1:1).le.'9' .and. call_a(2:2).ge.'0' .and. call_a(2:2).le.'9') then
+ nbadcrc=1; msg37=' '; return; endif
+ if(call_b(1:1).ge.'0' .and. call_b(1:1).le.'9' .and. call_b(2:2).ge.'0' .and. call_b(2:2).le.'9') then
+ nbadcrc=1; msg37=' '; return; endif
\ No newline at end of file diff --git a/lib/ft8var/callsign_q.f90 b/lib/ft8var/callsign_q.f90 new file mode 100755 index 00000000..5e453a3f --- /dev/null +++ b/lib/ft8var/callsign_q.f90 @@ -0,0 +1,26 @@ +
+! call may not start from 'Q', zero and two digits
+ if(callsign(1:1).eq.'Q' .or. callsign(1:1).eq.'0' .or. callsign(1:1).eq.'/') then
+ nbadcrc=1; msg37=' '; return; endif
+
+ if(callsign(1:1).ge.'0' .and. callsign(1:1).le.'9') then
+ if(callsign(2:2).ge.'0' .and. callsign(2:2).le.'9') then
+ nbadcrc=1; msg37=' '; return; endif
+ if(callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' .and. callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z' &
+ .and. callsign(4:4).ge.'A' .and. callsign(4:4).le.'Z') then
+ nbadcrc=1; msg37=' '; return; endif
+ endif
+
+ if(callsign(1:1).ge.'A' .and. callsign(1:1).le.'Z') then
+ if(callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' &
+ .and. callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z') then
+ nbadcrc=1; msg37=' '; return; endif
+ endif
+
+ if(callsign(1:1).ge.'0' .and. callsign(1:1).le.'9') then
+ if(callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' &
+ .and. callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z') then
+ if(callsign(1:3).ne.'3DA' .and. callsign(1:3).ne.'3XY') then
+ nbadcrc=1; msg37=' '; return; endif
+ endif
+ endif
\ No newline at end of file diff --git a/lib/ft8var/chkfalse8var.f90 b/lib/ft8var/chkfalse8var.f90 new file mode 100755 index 00000000..fc2a9840 --- /dev/null +++ b/lib/ft8var/chkfalse8var.f90 @@ -0,0 +1,603 @@ +subroutine chkfalse8var(msg37,i3,n3,nbadcrc,iaptype,lcall1hash)
+
+ use ft8_mod1, only : mycall,hiscall,hisgrid4
+ character msg37*37,decoded*22,callsign*12,calltmp*12,call_a*12,call_b*12, &
+ grid*12,callmask6*6
+ character*6 mask6(3)
+ integer, intent(in) :: i3,n3
+ logical(1) falsedec,lchkcall,lgvalid,lwrongcall
+ logical(1), intent(in) :: lcall1hash
+ data mask6/'001000','101000','011000'/
+
+ call_a=''
+ call_b=''
+! iaptype=0 non-AP decoder
+! iaptype=1 CQ message AP decoder
+
+! i3 n3 Bits Total Message type
+! ---------------------------------------------------------------------------------------
+! 0 0 FREE TEXT MSG 71 71
+! 0 1 K1ABC RR73; W9XYZ <KH1/KH7Z> -12 28 28 10 5 71 DXpedition Mode
+! 0 2 PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2)
+! 0 2 PA3XYZ 520093 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2)
+! 0 3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0 3 WA9XYZ KA1ABC 7D EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0 3 WA9XYZ G8ABC 1D DX 28 28 1 4 3 7 71 ARRL Field Day
+! 0 4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0 5 123456789ABCDEF012 71 71 Telemetry (18 hex)
+! 0 5 7123456789ABCDEF01 71 71 Telemetry (18 hex)
+! 0 5 71234567 71 71 Telemetry (18 hex)
+! 0 5 81234567 71 71 Telemetry (18 hex)
+! 0 5 8123456789ABCDEF01 71 71 Telemetry (18 hex)
+! 1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg, with std or non std callsign
+! 1 WA9XYZ KA1ABC R-11 28 1 28 1 1 15 74 Standard msg, with std or non std callsign
+! 1 CQ 039 P30KJE/R DR46
+! 2 PA1XYZ/P GM4ABC/P R FN42 28 1 28 1 1 15 74 EU VHF Contest
+! 2 CQ 039 P30KJE/P DR46
+! 3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest
+! 3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX)
+! 4 <WA9XYZ> PJ4/KA1ABC RR73 13 58 1 2 74 Nonstandard call
+! 4 <WA9XYZ> PJ4/KA1ABC 13 58 1 2 74 Nonstandard call
+! 4 PJ4/KA1ABC <WA9XYZ> RRR 13 58 1 2 74 Nonstandard call
+! 4 CQ ZW5STAYHOME 13 58 1 2 74 Nonstandard call
+
+! 'CQ 5NGX46MFKUE' 'CQ 53HDFKJEASD' 'CQ HDF53KJEASD' i3=4 n3=1
+! -23 0.3 1482 ~ CQ EQ3YCI/KVNA i3=4 n3=1
+! -23 -1.3 CQ P28Z58W/77M i3=4 n3=1
+ if(msg37(1:3).eq.'CQ ') then
+ callsign=''
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(i3.eq.4) then
+ islash=index(msg37,'/')
+ if(islash.le.0) then
+ callsign=trim(msg37(ispc1+1:))
+ nlencall=len_trim(callsign)
+ if(nlencall.lt.1) return
+ ispccall=index(callsign,' ')
+! CQ 9D6T0GA4 Z space inside callsign of any length: protocol violation, or last char is digit
+ if(ispccall.lt.nlencall .or. callsign(nlencall:nlencall).lt.':') then
+ go to 900
+ endif
+ else
+ if(islash.gt.ispc1 .and. islash.lt.ispc2) then
+ if(islash-ispc1.le.ispc2-islash) then
+ callsign=msg37(islash+1:ispc2-1)
+ else
+ callsign=msg37(ispc1+1:islash-1)
+ endif
+ endif
+ endif
+
+ include 'callsign_q.f90'
+
+ if(islash.gt.0) then
+ falsedec=.false.
+ call chkflscallvar('CQ ',callsign,falsedec)
+ if(falsedec) go to 900
+ else
+ nlen=len_trim(callsign)
+ if(nlen.ge.10) then
+ falsedec=.false.
+ call chklong8(callsign,falsedec)
+ if(falsedec) go to 900
+ else if(nlen.eq.6 .and. index(callsign,'/').lt.1) then
+! 'CQ VK6ZRW' protocol violation, i3 for stdcall shall be equal to 1
+ do i=1,6
+ if(callsign(i:i).gt.'/' .and. callsign(i:i).lt.':') then
+ callmask6(i:i)='1'
+ else
+ callmask6(i:i)='0'
+ endif
+ enddo
+
+ falsedec=.false.
+ do i=1,3
+ if(callmask6.eq.mask6(i)) then
+ falsedec=.true.
+ exit
+ endif ! standard callsign, false decode
+ enddo
+ if(falsedec) go to 900
+ endif
+ endif
+
+! i=1 AP mask iaptype 1 false decodes
+! -23 0.9 2630 ~ CQ P5RXL MK92 *
+! -24 0.3 550 ~ CQ DZ0BIL/R AD94 *
+! -7 0.2 400 ~ CQ LI9NAI/R CF97 * in some noisy setups such decodes possible with a high SNR
+
+ else if(iaptype.eq.1) then
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(msg37(ispc2-2:ispc2-1).eq.'/R' .or. &
+ msg37(ispc2-2:ispc2-1).eq.'/P') then
+ callsign=msg37(ispc1+1:ispc2-3)
+ else
+ callsign=msg37(ispc1+1:ispc2-1)
+ endif
+
+ include 'callsign_q.f90'
+
+ grid=''
+ if(ispc3-ispc2.eq.5 .and. msg37(ispc2+1:ispc2+1).gt.'@' .and. &
+ msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') grid=msg37(ispc2+1:ispc3-1)
+ if(len_trim(grid).eq.4) then
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+ endif
+
+ if(i3.eq.4) then
+! CQ Y09Q7/SS60M i3=4 n3=1
+ callsign=''
+ callsign=trim(msg37(4:))
+ islash=index(callsign,'/')
+ islash2=index(callsign(islash+1:),'/')
+ nlencall=len_trim(callsign)
+ if(nlencall.eq.11 .and. islash.gt.0 .and. islash2.lt.1) then
+
+ if(islash.lt.7) then
+ if((callsign(islash+1:islash+1).lt.':' .and. &
+ callsign(islash+2:islash+2).lt.':') .or. &
+ callsign(islash+1:islash+1).eq.'Q' .or. &
+ callsign(nlencall:nlencall).lt.':') go to 900
+ endif
+
+ if(islash.gt.5) then
+ if(callsign(islash-1:islash-1).lt.':' .or. &
+ (callsign(1:1).lt.':' .and. callsign(2:2).lt.':') .or. &
+ callsign(1:1).eq.'Q') go to 900
+ endif
+
+ if(islash.gt.4 .and. islash.lt.8) then
+ call_a=''
+ call_b=''
+ call_a=callsign(1:islash-1)
+ call_b=callsign(islash+1:)
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+ endif
+
+! CQ 039 P30KJE/R DR46 i3=1 n3=5
+! CQ 039 P30KJE/P DR46 i3=2 n3=5
+ if(msg37(4:4).lt.':' .and. msg37(4:4).gt.'/' .and. msg37(7:7).eq.' ' &
+ .and. (i3.eq.1 .or. i3.eq.2)) then
+ islash=index(msg37,'/')
+ if(islash.gt.10 .and. islash.lt.15) then
+ callsign=''
+ grid=''
+ callsign=msg37(8:islash-1)
+ grid=msg37(islash+3:islash+6)
+ nlengrid=len_trim(grid)
+ if(nlengrid.eq.4 .and. grid(1:1).gt.'@' .and. grid(4:4).lt.':') then
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+ falsedec=.false.
+ call chkflscallvar('MYCALL ',callsign,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+
+! CQ CJ3OPE/R FP61 i3=1
+! CQ KU3XIK NN41
+ if(i3.eq.1 .and. iaptype.eq.0) then
+ callsign=''
+ grid=''
+ islash=index(msg37,'/R ')
+ if(islash.gt.6) then
+ callsign=msg37(4:islash-1)
+ grid=msg37(islash+3:islash+6)
+ else if(islash.lt.1) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(len_trim(msg37).eq.ispc3-1) then
+ callsign=msg37(ispc1+1:ispc2-1)
+ grid=msg37(ispc2+1:ispc3-1)
+ else
+ return ! 4-word message, will be processed in ft8bvar.f90
+ endif
+ endif
+ nlengrid=len_trim(grid)
+ if(nlengrid.eq.4 .and. grid(1:1).gt.'@' .and. grid(4:4).lt.':') then
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+
+ if(islash.gt.6) then
+ falsedec=.false.
+ call chkflscallvar('MYCALL ',callsign,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+
+ return ! prevent further checking if message starts from 'CQ '
+! TO DO via patterns: '175715 -18 -0.1 2519 ~ CQ P2PSR6UWBHS'
+ endif
+
+ if(iaptype.eq.2) then ! message starts with user's callsign, 2nd callsign is random
+! ES1JA JA1QZQ/R R GD47
+! UA3ALE A70DDN/R OF23
+! ES6DO NH4CXV MA87
+! EA1AHY PW1BSL R GR47 i3=1
+! ES6DO ST0VQA R174 invalid message, can not be transmitted
+
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ callsign=''
+ grid=''
+ callsign=msg37(ispc1+1:ispc2-1)
+ islash=index(callsign,'/R')
+ if(islash.gt.3) then
+ calltmp=' '
+ calltmp=callsign(1:islash-1)
+ callsign=calltmp
+ endif
+
+ include 'callsign_q.f90'
+
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ indxr=index(msg37,' R ')
+ if(indxr.gt.7) then
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ if(ispc4-ispc3.eq.5) then
+ if(msg37(ispc3+1:ispc3+1).gt.'@' .and. &
+ msg37(ispc3+1:ispc3+1).lt.'S' .and. &
+ msg37(ispc3+2:ispc3+2).gt.'@' .and. &
+ msg37(ispc3+2:ispc3+2).lt.'S' .and. &
+ msg37(ispc3+3:ispc3+3).lt.':' .and. &
+ msg37(ispc3+4:ispc3+4).lt.':') then
+ grid=msg37(ispc3+1:ispc4-1)
+ else ! invalid message
+ go to 900
+ endif
+ endif
+ else if(indxr.lt.1) then
+ if(ispc3-ispc2.eq.5) then
+ if(msg37(ispc2+1:ispc2+1).gt.'@' .and. &
+ msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') then
+ grid=msg37(ispc2+1:ispc3-1)
+ else ! invalid message
+ go to 900
+ endif
+ endif
+ endif
+ if(len_trim(grid).eq.4) then
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+
+ return ! no need in other checks
+ endif
+
+ if(iaptype.eq.40) then ! AP mask '<mycall> ??? ???'
+! JH4PUL/3 BG4NSA RQ43 * reported false decodes
+! JH4PUL/3 M06FLK R AE10 * at least it is possible to transmit the message
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ callsign=''
+ grid=''
+ callsign=msg37(ispc1+1:ispc2-1)
+
+ include 'callsign_q.f90'
+
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ indxr=index(msg37,' R ')
+ if(indxr.gt.7) then
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ if(ispc4-ispc3.eq.5 .and. msg37(ispc3+1:ispc3+1).gt.'@' .and. &
+ msg37(ispc3+1:ispc3+1).lt.'S' .and. &
+ msg37(ispc3+2:ispc3+2).gt.'@' .and. &
+ msg37(ispc3+2:ispc3+2).lt.'S' .and. &
+ msg37(ispc3+3:ispc3+3).lt.':' .and. &
+ msg37(ispc3+4:ispc3+4).lt.':') grid=msg37(ispc3+1:ispc4-1)
+ else if(indxr.lt.1) then
+ if(ispc3-ispc2.eq.5 .and. msg37(ispc2+1:ispc2+1).gt.'@' .and. &
+ msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') grid=msg37(ispc2+1:ispc3-1)
+ endif
+
+ if(len_trim(grid).eq.4) then
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+ return ! no need in other checks for iaptype 40
+ endif
+
+! RV6ARZ CX7CO R NI25 ! mycall hiscall ??? AP mask false decode, both callsigns are correct, checking for valid grid
+! ES6DO TK60CNES R MJ79 ! non standard DXCall, iaptype 11
+! UA0ZZZ AA1AAA/1 R GC45 ! non standard DXCall, iaptype 11
+! JH4PUL/3 HB9CEX R PN76 * ! non standard mycall, iaptype 41
+! JH4PUL/3 JT1DN HB30 * ! non standard mycall, iaptype 41
+
+ if(iaptype.eq.3 .or. iaptype.eq.11 .or. iaptype.eq.21 .or. iaptype.eq.41) then
+ indxr=index(msg37,' R ')
+ if(iaptype.eq.21 .and. indxr.gt.0) go to 900 ! invalid message in Hound mode
+ islash1=index(msg37,'/')
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(ispc1.gt.3 .and. ispc2.gt.7) then
+ if(islash1.lt.ispc1 .or. (islash1.eq.ispc2-2 .and. &
+ msg37(ispc2-1:ispc2-1).lt.':' )) then ! AA1AAA/1 can be first or 2nd callsign
+ if(msg37(1:ispc1-1).eq.mycall .and. &
+ msg37(ispc1+1:ispc2-1).eq.hiscall) then
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ grid=''
+ if(indxr.gt.7) then
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ if(ispc4-ispc3.eq.5 .and. msg37(ispc3+1:ispc3+1).gt.'@' &
+ .and. msg37(ispc3+1:ispc3+1).lt.'S' .and. &
+ msg37(ispc3+2:ispc3+2).gt.'@' .and. &
+ msg37(ispc3+2:ispc3+2).lt.'S' .and. &
+ msg37(ispc3+3:ispc3+3).lt.':' .and. &
+ msg37(ispc3+4:ispc3+4).lt.':') grid=msg37(ispc3+1:ispc4-1)
+ else if(indxr.lt.1) then
+ if(ispc3-ispc2.eq.5 .and. msg37(ispc2+1:ispc2+1).gt.'@' &
+ .and. msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') grid=msg37(ispc2+1:ispc3-1)
+ endif
+
+ if(len_trim(grid).eq.4 .and. grid.ne.hisgrid4) then
+ ! correctly decoded contest message
+ if(iaptype.eq.21) then
+ if(grid.eq.'RR73') then
+ ! AP mask 'mybcall hisbcall ???' can trigger RR73 message
+ return
+ else
+ go to 900
+ endif
+ endif
+ call chkgridvar(hiscall,grid,lchkcall,lgvalid,lwrongcall)
+ if(grid.eq.'RR73') then
+ lgvalid = .true.
+ else
+ if(.not.lgvalid) go to 900
+ endif
+ endif
+ endif
+ endif
+ endif
+ return ! no need in other checks
+ endif
+
+ if((i3.ge.1 .and. i3.le.3) .and. (index(msg37,' R ').gt.0 .or. &
+ index(msg37,'/R ').gt.0 .or. index(msg37,'/P ').gt.0)) then
+
+! i3=1: 'VF5RMP/P OW3ATG/P R MF' '378YYA/R 9H5PQU R OL53'
+! i3=2: 'YT4MEY/P WL8QEW R IR03'
+! i3=1: 'ER2XXD 8L7UWC R 529 26'
+! i3=3 n3=1: '1M8JSH TI0CZQ R 539 42'
+! i3=2 n3=5: 'DQ2VF/P J2OON KG37'
+! 'N40RTH AD2WPI/R MG62'
+
+ islash1=index(msg37,'/')
+ call_a=''
+ call_b=''
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(islash1.lt.1 .and. ispc1.gt.3 .and. ispc2.gt.7) then
+ call_a=msg37(1:ispc1-1)
+ call_b=msg37(ispc1+1:ispc2-1)
+ if(call_b.ne.hiscall) then
+ include 'call_q.f90'
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+
+ if(islash1.gt.0 .and. ispc1.gt.3 .and. ispc2.gt.7) then
+ islash2=index(msg37((islash1+1):),'/')+islash1
+ if(islash1.gt.ispc1) then
+ call_a=msg37(1:ispc1-1)
+ call_b=msg37(ispc1+1:islash1-1)
+ else
+ call_a=msg37(1:islash1-1)
+ if(islash2.gt.islash1) then
+ call_b=msg37(ispc1+1:islash2-1)
+ else
+ call_b=msg37(ispc1+1:ispc2-1)
+ endif
+ endif
+ include 'call_q.f90'
+ if(call_a.ne.mycall .and. call_b.ne.hiscall) then
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+ endif
+
+! i3=1 n3=4
+! 000189 -23 0.4 300 ~ <...> QG6GFE CQ14
+! 110015 -21 -0.0 2050 ~ <...> NF7OEX CP03
+! check if grid is correct for call_2
+
+ if(lcall1hash .and. i3.eq.1) then
+ ! hash can be associated with a valid callsign in the table
+ ispc1=index(msg37,' ')
+ if(msg37(1:ispc1-1).ne.mycall) then
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ callsign=''
+ grid=''
+ callsign=msg37(ispc1+1:ispc2-1)
+ islash=index(callsign,'/')
+ if(islash.lt.1) then
+ include 'callsign_q.f90'
+ if(callsign.ne.hiscall) then
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(ispc3-ispc2.eq.5 .and. msg37(ispc2+1:ispc2+1).gt.'@' .and. &
+ msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') then
+ grid=msg37(ispc2+1:ispc3-1)
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) go to 900
+ endif
+ endif
+ endif
+ endif
+ endif
+
+! i3=1 n3=1 '4P6NPC 5M5UJG BK49'
+! i3=3 n3=1 '8Z7TLB JQ0OTZ 589 02'
+! i3=0 n3=3 'CE3NTP 4C2DWN 5E ONE'
+
+ if(iaptype.ne.2) then
+ if(((i3.eq.1 .or. i3.eq.3) .and. index(msg37,' R ').le.0 .and. &
+ index(msg37,'/').le.0) .or. (i3.eq.0 .and. n3.eq.3)) then
+ if(msg37(1:2).eq.'<.') go to 2
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(ispc1.gt.3 .and. ispc2.gt.7) then
+ call_a=msg37(1:ispc1-1)
+ if(call_a.eq.mycall) go to 2 ! exception to incoming calls
+ call_b=msg37(ispc1+1:ispc2-1)
+ include 'call_q.f90'
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+ endif
+
+2 continue
+
+ if(i3.eq.4) then
+ ibrace1=index(msg37,'<.')
+ if(index(msg37,'<.').gt.4) then
+ callsign=''
+ callsign=msg37(1:ibrace1-2)
+ islash=index(callsign,'/')
+ nlencall=len_trim(callsign)
+ if(nlencall.lt.1) go to 4
+
+! i3=4 n3=2 '6397X6JN637 <...> RRR'
+! 'R 5QCDOIY9 <...> RR73'
+ if(index(trim(callsign),' ').gt.0 .or. (islash.lt.1 .and. &
+ callsign(nlencall:nlencall).lt.':')) go to 900
+ include 'callsign_q.f90'
+ falsedec=.false.
+ call chklong8(callsign,falsedec)
+ if(falsedec) go to 900
+ endif
+ if(msg37(1:2).eq.'<.' .or. index(msg37,'.>').gt.4) then
+!'<...> 104J71MFOT9 RR73'
+! i3=4 n3=0 '<...> /7ZZZZ/ /8'
+! i3=4 n3=2 '<...> 6HGLDZ 5IN2 RRR'
+ callsign=''
+ nlenmsg=len_trim(msg37)
+ if(msg37(1:2).eq.'<.') then
+ if(msg37(nlenmsg-4:nlenmsg).eq.' RR73') then
+ callsign=msg37(7:nlenmsg-5)
+ else if(msg37(nlenmsg-2:nlenmsg).eq.' 73') then
+ callsign=msg37(7:nlenmsg-3)
+ else if(msg37(nlenmsg-3:nlenmsg).eq.' RRR') then
+ callsign=msg37(7:nlenmsg-4)
+ else
+ callsign=msg37(7:nlenmsg)
+ endif
+ else
+ ibracket=index(msg37,'<.')
+ callsign=msg37(1:ibracket-2)
+ endif
+ nlencall=len_trim(callsign)
+ if(nlencall.gt.0) then
+ ispace=index(callsign(1:nlencall),' ')
+ islash=index(callsign,'/')
+ if(ispace.gt.0 .or. (islash.lt.1 .and. &
+ callsign(nlencall:nlencall).lt.':') .or. &
+ islash.eq.nlencall) go to 900
+
+! KY2HTW/0O5M <...> i3=4 n3=0
+ if(islash.gt.4) then
+ islash2=index(callsign(islash+1:),'/')
+ if(nlencall.eq.11 .and. islash2.lt.1) then
+ if(islash.lt.7) then
+ if((callsign(islash+1:islash+1).lt.':' .and. &
+ callsign(islash+2:islash+2).lt.':') .or. &
+ callsign(islash+1:islash+1).eq.'Q' .or. &
+ callsign(nlencall:nlencall).lt.':') go to 900
+ endif
+
+ if(islash.gt.5) then
+ if(callsign(islash-1:islash-1).lt.':' .or. &
+ (callsign(1:1).lt.':' .and.callsign(2:2).lt.':') &
+ .or. callsign(1:1).eq.'Q') go to 900
+ endif
+
+ if(islash.gt.4 .and. islash.lt.8) then
+ call_a=''
+ call_b=''
+ call_a=callsign(1:islash-1)
+ call_b=callsign(islash+1:)
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+ endif
+ include 'callsign_q.f90'
+ falsedec=.false.
+ call chklong8(callsign,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+! '<...> T99LMF GC41' need to understand how to check such message
+ endif
+
+4 continue
+
+ if(i3.eq.3 .and. msg37(1:3).eq.'TU;') then
+!i3=3 n3=3 'TU; QV4UPP 632TGU 529'
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(ispc2.gt.7 .and. ispc3.gt.11) then
+ call_a=msg37(ispc1+1:ispc2-1)
+ call_b=msg37(ispc2+1:ispc3-1)
+ include 'call_q.f90'
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) go to 900
+ endif
+ endif
+
+ if(i3.eq.0 .and. n3.eq.0) then
+! 'J/.ZM1R-D1Q89'
+ if(index(msg37,'/.').gt.0) go to 900
+ decoded=msg37(1:22)
+ falsedec=.false.
+ call filtersfreevar(decoded,falsedec)
+ if(falsedec) go to 900
+ endif
+
+! CQ_RLXA 551626 ^J65XI
+ if(i3.eq.0 .and. (msg37(1:3).eq.'CQ_' .or. index(msg37,'^').gt.0)) go to 900
+ go to 999
+
+900 nbadcrc=1
+ msg37=''
+
+999 return
+end subroutine chkfalse8var
diff --git a/lib/ft8var/chkflscallvar.f90 b/lib/ft8var/chkflscallvar.f90 new file mode 100755 index 00000000..ff7fe643 --- /dev/null +++ b/lib/ft8var/chkflscallvar.f90 @@ -0,0 +1,18 @@ +subroutine chkflscallvar(call_a,call_b,falsedec)
+
+ character*12 call_a,call_b
+ logical(1) falsedec,lfound
+
+ if(call_a(1:2).eq.'<.') return
+ falsedec=.true.; lfound=.false.
+!print *,"11","'"//call_a//"'","'"//call_b//"'"
+ if(call_a.eq.'MYCALL ' .or. call_a.eq.'CQ ') then
+ call searchcallsvar(call_b," ",lfound); if(lfound) falsedec=.false.
+ else if(call_b(1:1).eq.'<') then
+ call searchcallsvar(call_a," ",lfound); if(lfound) falsedec=.false.
+ else
+ call searchcallsvar(call_a,call_b,lfound); if(lfound) falsedec=.false.
+ endif
+
+ return
+end subroutine chkflscallvar
\ No newline at end of file diff --git a/lib/ft8var/chkgridvar.f90 b/lib/ft8var/chkgridvar.f90 new file mode 100755 index 00000000..f9f88813 --- /dev/null +++ b/lib/ft8var/chkgridvar.f90 @@ -0,0 +1,3392 @@ +subroutine chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+
+ character, intent(in) :: callsign*12,grid*12
+ logical(1) lchkcall,lgvalid,lwrongcall
+
+lchkcall=.false.; lgvalid=.false.; lwrongcall=.false.
+
+if(grid(1:1).gt.'@' .and. grid(1:1).lt.'J') then
+ if(grid(1:1).eq.'A' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'E') .or. grid(2:2).eq.'M' .or. grid(2:2).eq.'N' .or. &
+ grid(2:2).eq.'Q' .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'B' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'G') .or. grid(2:2).eq.'M' .or. grid(2:2).eq.'N' .or. &
+ grid(2:2).eq.'Q' .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'C' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'G') .or. &
+ (grid(2:2).eq.'G' .and. grid(3:3).gt.'7' .and. grid(4:4).lt.'4') .or. &
+ (grid(2:2).eq.'I' .and. grid(3:3).gt.'0' .and. grid(4:4).gt.'1') .or. &
+ (grid(2:2).gt.'I' .and. grid(2:2).lt.'M') .or. grid(2:2).eq.'Q' .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'D' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'G') .or. (grid(2:2).gt.'G'.and.grid(2:2).lt.'K').or. &
+ (grid(2:2).eq.'G' .and. grid(3:4).ne.'52' .and. grid(3:4).ne.'73') .or. &
+ grid(2:2).eq.'Q' .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'E' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'C') .or. &
+ (grid(2:2).eq.'C' .and. grid(3:4).ne.'41') .or. (grid(2:2).eq.'F' .and. grid(3:4).ne.'96') .or. &
+ (grid(2:2).gt.'C' .and. grid(2:2).lt.'F') .or. (grid(2:2).eq.'G' .and. grid(3:4).ne.'93') .or.grid(2:2).eq.'H'.or. &
+ grid(2:2).eq.'Q' .or. (grid(2:2).eq.'R' .and. grid(3:4).ne.'60'))) then; lchkcall=.true. ! VY0
+
+ else if(grid(1:1).eq.'F' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'D') .or. (grid(2:2).eq.'Q'.and.grid(3:3).lt.'3').or. &
+ grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'G' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'C') .or. (grid(2:2).gt.'K'.and.grid(2:2).lt.'N').or. &
+ (grid(2:2).eq.'K' .and. grid(3:3).gt.'0') .or. (grid(2:2).eq.'N' .and. grid(3:3).gt.'3') .or. &
+ (grid(2:2).eq.'Q' .and. grid(4:4).gt.'4') .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'H' .and. (grid(2:2).eq.'A' .or. (grid(2:2).eq.'B' .and. grid(3:4).ne.'22') .or. & ! LU1ZG in HB22QD
+ grid(2:2).eq.'C' .or. (grid(2:2).gt.'D'.and.grid(2:2).lt.'H') .or. &
+ grid(2:2).eq.'J' .or. grid(2:2).eq.'L' .or. grid(2:2).eq.'N' .or. grid(2:2).eq.'O' .or. &
+ (grid(2:2).eq.'K' .and. grid(3:3).lt.'7') .or. (grid(2:2).eq.'M' .and. grid(4:4).lt.'6') .or. &
+ (grid(2:2).eq.'Q' .and. grid(4:4).gt.'0') .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'I' .and. (grid(2:2).eq.'A' .or. (grid(2:2).gt.'B' .and. grid(2:2).lt.'F') .or. &
+ (grid(2:2).eq.'B' .and. grid(3:4).ne.'59') .or. & ! DP0GVN
+ (grid(2:2).eq.'F' .and. grid(3:4).ne.'32') .or. grid(2:2).eq.'G' .or. (grid(2:2).eq.'H' .and.grid(3:3).ne.'7').or. &
+ (grid(2:2).eq.'I' .and. grid(3:4).ne.'22') .or. (grid(2:2).eq.'O' .and. grid(3:3).lt.'3') .or. &
+ (grid(2:2).eq.'P' .and. grid(4:4).gt.'7') .or. (grid(2:2).eq.'Q' .and. grid(4:4).gt.'1') .or. grid(2:2).eq.'R')) &
+ then; lchkcall=.true.
+ endif
+
+else if(grid(1:1).gt.'I' .and. grid(1:1).lt.'S') then
+
+ if(grid(1:1).eq.'J' .and. (grid(2:2).eq.'C' .or. &
+ (grid(2:2).eq.'A' .and. grid(3:4).ne.'00') .or. & ! KC4AAA
+ (grid(2:2).eq.'B' .and. grid(3:4).ne.'59') .or. & ! Novolazarevskaya
+ (grid(2:2).eq.'D' .and. grid(3:4).ne.'15') .or. grid(2:2).eq.'E' .or. (grid(2:2).eq.'F' .and. grid(3:3).lt.'8') .or. &
+ (grid(2:2).eq.'G' .and. grid(3:3).lt.'6') .or. (grid(2:2).eq.'H' .and. grid(3:3).lt.'5') .or. &
+ (grid(2:2).eq.'I' .and. grid(3:3).lt.'2') .or. (grid(2:2).eq.'R' .and. grid(4:4).gt.'0'))) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'K' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'C') .or. &
+ (grid(2:2).eq.'C' .and. grid(3:4).ne.'90') .or. grid(2:2).eq.'D' .or. & ! 8J1RL
+ (grid(2:2).eq.'E' .and. grid(3:4).ne.'83' .and. grid(3:4).ne.'93') .or. (grid(2:2).eq.'F' .and. grid(4:4).lt.'5') .or. &
+ (grid(2:2).eq.'R' .and. grid(4:4).gt.'0'))) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'L' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'E') .or. &
+ (grid(2:2).eq.'E' .and. grid(3:4).ne.'53' .and. grid(3:4).ne.'54' .and. grid(3:4).ne.'63') .or. grid(2:2).eq.'F' .or. &
+ (grid(2:2).eq.'G' .and. grid(4:4).lt.'4') .or. (grid(2:2).eq.'J' .and. grid(3:3).gt.'5') .or. &
+ (grid(2:2).eq.'Q' .and. grid(4:4).lt.'5' .and. grid(4:4).lt.'9') .or. &
+ (grid(2:2).eq.'R' .and. grid(4:4).gt.'1'))) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'M' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'D') .or. &
+ (grid(2:2).eq.'D' .and. grid(3:4).ne.'66' .and. grid(3:4).ne.'67' .and. grid(3:4).ne.'49') .or. &
+ (grid(2:2).eq.'E' .and. grid(3:4).ne.'40' .and. grid(3:4).ne.'41' .and. grid(3:4).ne.'50') .or. &
+ (grid(2:2).eq.'F' .and. grid(3:4).ne.'81' .and. grid(3:4).ne.'82') .or. grid(2:2).eq.'G' .or. &
+ (grid(2:2).eq.'H' .and. grid(3:4).ne.'10') .or. (grid(2:2).eq.'I' .and. grid(3:3).lt.'5') .or. &
+ (grid(2:2).eq.'J' .and. grid(3:3).lt.'6') .or. (grid(2:2).eq.'K' .and. grid(3:3).lt.'5') .or. &
+ (grid(2:2).eq.'R' .and. grid(4:4).gt.'1'))) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'N' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'H') .or. &
+ (grid(2:2).eq.'H' .and. grid(3:4).ne.'87' .and. grid(3:4).ne.'88') .or. &
+ (grid(2:2).eq.'I' .and. grid(3:3).lt.'9' .and. grid(3:4).ne.'89') .or. &
+ (grid(2:2).eq.'J' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6') .or. &
+ (grid(2:2).eq.'R' .and. grid(4:4).gt.'1'))) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'O' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'F') .or. &
+ (grid(2:2).eq.'F' .and. grid(3:3).lt.'7') .or. (grid(2:2).eq.'G' .and. grid(3:3).lt.'6') .or. &
+ (grid(2:2).eq.'H' .and. grid(3:4).ne.'90' .and. grid(3:4).ne.'92' .and. grid(3:4).ne.'29' .and. grid(3:4).ne.'99').or. &
+ grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'P' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'F') .or. (grid(2:2).eq.'F'.and.grid(4:4).lt.'2').or. &
+ (grid(2:2).eq.'K' .and. grid(3:3).gt.'3' .and. grid(3:4).ne.'90') .or. &
+ (grid(2:2).eq.'Q' .and. grid(4:4).gt.'6') .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'Q' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'D') .or. &
+ (grid(2:2).eq.'D' .and. grid(3:4).ne.'94' .and. grid(3:4).ne.'95') .or. (grid(2:2).eq.'E' .and. grid(4:4).lt.'6') .or. &
+ (grid(2:2).eq.'F' .and. grid(3:3).gt.'6' .and. grid(3:4).ne.'98') .or. &
+ (grid(2:2).eq.'K' .and. grid(3:3).gt.'2' .and. grid(3:4).ne.'36') .or. &
+ (grid(2:2).eq.'L' .and. grid(3:3).gt.'2' .and. grid(3:4).ne.'64' .and. grid(3:4).ne.'74') .or. &
+ (grid(2:2).eq.'M' .and. grid(3:3).gt.'0' .and. grid(3:4).ne.'19') .or. &
+ (grid(2:2).eq.'N' .and. grid(3:3).gt.'7') .or. &
+ (grid(2:2).eq.'Q' .and. grid(4:4).gt.'7') .or. grid(2:2).eq.'R')) then; lchkcall=.true.
+
+ else if(grid(1:1).eq.'R' .and. ((grid(2:2).gt.'@' .and. grid(2:2).lt.'D') .or. &
+ (grid(2:2).eq.'D' .and. grid(3:4).ne.'47' .and. grid(3:4).ne.'29' .and. grid(3:4).ne.'39') .or. &
+ (grid(2:2).eq.'K' .and. grid(4:4).gt.'4' .and. grid(3:4).ne.'39') .or. (grid(2:2).gt.'K' .and. grid(2:2).lt.'O') .or. &
+ (grid(2:2).eq.'O' .and. grid(4:4).eq.'0') .or. (grid(2:2).eq.'Q' .and. grid(4:4).gt.'1') .or. grid(2:2).eq.'R')) &
+ then; lchkcall=.true.
+ endif
+
+else if (grid(1:1).gt.'/' .and. grid(1:1).lt.':') then ! 0..9
+ lchkcall=.true.
+endif
+
+if(.not.lchkcall) then
+
+ if(callsign(1:1).gt.'K' .and. callsign(1:1).lt.'[') then; go to 2
+ else if(callsign(1:1).gt.'/' .and. callsign(1:1).lt.':') then; go to 4
+ endif
+
+ if(callsign(1:1).eq.'A') then
+
+! USA AA..AL,K,N,W
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'M') then
+ if((grid(1:2).eq.'FM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'EL' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'DL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'EM' .or. grid(1:2).eq.'DM' .or. grid(1:2).eq.'EN' .or. &
+ (grid(1:2).eq.'CM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'DN' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. &
+ grid(1:2).eq.'BP' .or. &
+ (grid(1:2).eq.'BO' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AP' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ grid(1:4).eq.'FK28' .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'BL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'BK' .and. (grid(3:4).eq.'19' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'AL' .and. (grid(3:4).eq.'91' .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. &
+ grid(3:4).eq.'27' .or. grid(3:4).eq.'36' .or. grid(3:4).eq.'45' .or. grid(3:4).eq.'64' .or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:3).eq.'QK2' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'RO' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3').or. &
+ grid(3:4).eq.'63')) .or. &
+ grid(1:4).eq.'AP30' .or. grid(1:4).eq.'QK36' .or. grid(1:4).eq.'QL20' .or. grid(1:4).eq.'RK39' .or. &
+ grid(1:4).eq.'AK56' .or. grid(1:4).eq.'AH48' .or. grid(1:4).eq.'JA00' .or. grid(1:4).eq.'RB32' .or. &
+ grid(1:4).eq.'CP00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FM' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'24')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' &
+ .and. grid(3:4).ne.'28'.and. grid(3:4).ne.'58') .or. grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. &
+ grid(3:4).eq.'14')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DL' .and. (grid(3:4).eq.'78' .or. grid(3:4).eq.'88')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EN' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ ((grid(3:3).eq.'8' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9' .and. grid(3:3).ne.'2'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CM' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FN' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. grid(3:4).eq.'15' .or. grid(3:4).eq.'52')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'BO' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'3'.and.grid(4:4).lt.'9').or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AP' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(4:4).gt.'3' .and. grid(4:4).lt.':'))) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'63' .or. &
+ grid(3:4).eq.'67' .or. grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AO' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'2' .and. grid(4:4).lt.'7') .or. &
+ grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':' .and. grid(4:4).ne.'6') .or. &
+ ((grid(3:3).eq.'6' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'62' .or. grid(3:4).eq.'97' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'87' .or.grid(3:4).eq.'31')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'BL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21' .or. &
+ grid(3:4).eq.'22')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'RO' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'71')) then; lgvalid=.false.
+ endif
+endif
+
+! Australia AX,VH..VN,VZ
+ else if(callsign(1:2).eq.'AX') then
+ if((grid(1:2).eq.'QG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7') .or. &
+ (grid(1:2).eq.'QF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7') .or. &
+ (grid(1:2).eq.'PF' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'OF' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'QE' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and.grid(4:4).gt.'5'.and. grid(4:4).lt.':').or. &
+ grid(3:4).eq.'19')) .or. &
+ (grid(1:2).eq.'QH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'OG' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ grid(1:2).eq.'PG' .or. grid(1:2).eq.'PH') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'QF' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PF' .and. ((grid(3:3).gt.'/'.and.grid(3:3).lt.'8'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'7') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'7') .or. grid(3:4).eq.'57')) then; lgvalid=.false.
+ else if(grid(1:4).eq.'OF74') then; lgvalid=.false.
+ else if(grid(1:2).eq.'QH' .and. ((grid(3:3).eq.'3' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. grid(3:4).eq.'09')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OG' .and. (grid(3:4).eq.'60' .or. grid(3:4).eq.'69')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PH' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':' .and. &
+ grid(4:4).ne.'5' .and. grid(4:4).ne.'6') .or. &
+ (grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'9' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'59' .or. grid(3:4).eq.'79' .or. grid(3:4).eq.'89')) then; lgvalid=.false.
+ endif
+endif
+
+! Pakistan 6P..6S, AP..AS
+ else if(callsign(2:2).gt.'O' .and. callsign(2:2).lt.'T') then
+ if((grid(1:2).eq.'MM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'ML' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'33'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'MM' .and. grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') then; lgvalid=.false.
+ else if(grid(1:2).eq.'ML' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'07')) then; lgvalid=.false.
+ endif
+endif
+
+! Spain AM..AO,EA..EH
+ else if(callsign(1:1).eq.'A' .and. callsign(2:2).gt.'L' .and. callsign(2:2).lt.'P') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4' .and. &
+ grid(3:4).ne.'50').or. &
+ (grid(1:2).eq.'IM' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'12' .or. grid(3:4).eq.'13' .or. grid(3:4).eq.'75' .or. grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'JN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'20')) .or. &
+ (grid(1:2).eq.'JM' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09' .or.grid(3:4).eq.'19'.or.grid(3:4).eq.'29')).or. &
+ (grid(1:2).eq.'IL' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(4:4).eq.'8' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. grid(3:4).eq.'39'))) lgvalid=.true.
+
+! Botswana 8O,A2
+ else if(callsign(1:2).eq.'A2') then
+ if((grid(1:2).eq.'KG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ (grid(1:2).eq.'KH' .and. (grid(3:4).eq.'22' .or. grid(3:4).eq.'30')) .or. &
+ (grid(1:2).eq.'KG' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'47'))) lgvalid=.true.
+
+! Tonga A3
+ else if(callsign(1:2).eq.'A3') then
+ if((grid(1:2).eq.'AG' .and. (grid(3:4).eq.'28' .or.grid(3:4).eq.'29'.or.grid(3:4).eq.'06'.or.grid(3:4).eq.'07')).or. &
+ (grid(1:2).eq.'AH' .and. (grid(3:4).eq.'21' .or.grid(3:4).eq.'31'.or.grid(3:4).eq.'24'.or.grid(3:4).eq.'34'))) &
+ lgvalid=.true.
+
+! Oman A4
+ else if(callsign(1:2).eq.'A4') then
+ if((grid(1:2).eq.'LL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Bhutan A5
+ else if(callsign(1:2).eq.'A5') then
+ if(grid(1:2).eq.'NL' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.'9') &
+ lgvalid=.true.
+
+! United Arab Emirates A6
+ else if(callsign(1:2).eq.'A6') then
+ if(grid(1:2).eq.'LL' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and.grid(4:4).gt.'1'.and.grid(4:4).lt.'6').or. &
+ grid(3:4).eq.'53' .or. grid(3:4).eq.'54')) lgvalid=.true.
+
+! Qatar A7
+ else if(callsign(1:2).eq.'A7') then
+ if((grid(1:3).eq.'LL5' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.'7') .or. grid(1:4).eq.'LL65') lgvalid=.true.
+
+! Bahrain A9
+ else if(callsign(1:2).eq.'A9') then
+ if(grid(1:3).eq.'LL5' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.'7') lgvalid=.true.
+
+! Argentina AY,AZ, L1..L9, LO..LW
+ else if(callsign(1:2).eq.'AY' .or. callsign(1:2).eq.'AZ') then
+ if((grid(1:2).eq.'GF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FF' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FG' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'GG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'9') .or. &
+ (grid(1:2).eq.'FD' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'GC07' .or. grid(1:4).eq.'GC16') lgvalid=.true. ! LU1ZB in GC16
+
+if(lgvalid) then
+ if(grid(1:2).eq.'GF' .and. (grid(3:4).eq.'16' .or. grid(3:4).eq.'17')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FG' .and. (grid(3:4).eq.'56' .or. grid(3:4).eq.'57')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GG' .and. (grid(3:4).eq.'20' .or. grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. &
+ grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. ((grid(3:3).eq.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'70' .or. grid(3:4).eq.'73')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'2'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':'))) then; lgvalid=.false.
+ endif
+endif
+
+! India 8T..8Y,AT..AW,VT..VW
+ else if(callsign(1:1).eq.'A' .and. callsign(2:2).gt.'S' .and. callsign(2:2).lt.'X') then
+ if((grid(1:2).eq.'MJ' .and. (grid(3:4).eq.'99' .or. grid(3:4).eq.'89' .or. grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'68')).or. &
+ (grid(1:2).eq.'MK' .and. ((grid(3:3).gt.'5'.and.grid(3:3).lt.':').or.grid(3:4).eq.'51'.or.grid(3:4).eq.'52')).or. &
+ (grid(1:2).eq.'NK' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or.grid(3:4).eq.'39')).or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(1:4).eq.'NM00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'MK' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'5') then; lgvalid=.false.
+ else if(grid(1:2).eq.'NK' .and. (grid(3:4).eq.'26' .or. grid(3:4).eq.'27')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'ML' .and. ((grid(3:3).gt.'4'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'5'.or.grid(4:4).eq.'8'.or. &
+ grid(4:4).eq.'9')) .or. grid(3:4).eq.'58' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NL' .and. ((grid(4:4).eq.'9' .and. grid(3:3).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(4:4).eq.'8' .and. grid(3:3).gt.'0' .and. grid(4:4).lt.'5') .or.grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'62')) then; lgvalid=.false.
+ endif
+endif
+
+! Liberia 5L,5M,6Z,A8,D5,EL
+ else if(callsign(1:2).eq.'A8') then
+ if(grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' .and. &
+ grid(3:4).ne.'67' .and. grid(3:4).ne.'67') lgvalid=.true.
+
+ endif ! 'A'
+
+ else if(callsign(1:1).eq.'B') then
+ if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':' .and. callsign(3:3).gt.'/' .and. callsign(3:3).lt.':') return ! checkcall
+! China, Taiwan B, 3H..3U, XS
+ if(grid(1:2).eq.'OL' .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. grid(1:2).eq.'OM' .or. &
+ (grid(1:2).eq.'PM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(1:2).eq.'PN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8') .or. &
+ (grid(1:2).eq.'PO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ (grid(1:2).eq.'OK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'58' .or.grid(3:4).eq.'59')).or. &
+ grid(1:2).eq.'ON' .or. grid(1:4).eq.'OO90' .or. grid(1:4).eq.'OO91' .or. grid(1:2).eq.'NN' .or. grid(1:2).eq.'NM'.or. &
+ (grid(1:2).eq.'NL' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'MN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':')) lgvalid=.true.
+
+if(lgvalid) then
+! grid exceptions for Taiwan BM,BN,BO,BP,BQ,BU,BV,BW,BX
+ if((callsign(2:2).gt.'L' .and. callsign(2:2).lt.'R') .or. (callsign(2:2).gt.'T' .and. callsign(2:2).lt.'Y')) then
+ if(grid(1:4).ne.'PL04' .and. grid(1:4).ne.'PL03' .and. grid(1:4).ne.'PL05' .and. grid(1:4).ne.'PL02' .and. &
+ grid(1:4).ne.'PL01' .and. grid(1:4).ne.'OL93' .and. grid(1:4).ne.'PL15' .and. grid(1:4).ne.'OL80') lgvalid=.false.
+ endif
+endif
+if(lgvalid) then
+ if(grid(1:2).eq.'NL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'7'.and. &
+ grid(3:4).ne.'83' .and. grid(3:4).ne.'84' .and. grid(3:4).ne.'85') .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'87')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'ON' .and.((grid(3:3).gt.'/'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'76' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PN' .and. ((grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'40' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'59' .or. &
+ grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).eq.'0') .or. &
+ grid(3:4).eq.'11' .or. grid(3:4).eq.'21')) then; lgvalid=.false.
+ endif
+endif
+if(.not.lgvalid) then
+! Spratly Islands 1S,9M0,BM9S,BN9S,BO9S,BP9S,BQ9S,BU9S,BV9S,BW9S,BX9S
+ if(callsign(3:4).eq.'9S' .and. ((callsign(2:2).gt.'K' .and. callsign(2:2).lt.'R') .or. (callsign(2:2).gt.'T'.and. &
+ callsign(2:2).lt.'Y'))) then
+ if((grid(1:2).eq.'OK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+endif
+
+ endif ! 'B'
+
+ else if(callsign(1:1).eq.'C') then
+
+ ! Chile 3G,CA..CE,XQ,XR
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'F') then
+ if((grid(1:2).eq.'FF' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FG' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'8'))) .or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52')) .or. &
+ (grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'53' .or. grid(3:4).eq.'85')) .or. &
+ grid(1:4).eq.'EF96' .or. grid(1:4).eq.'FF06' .or. grid(1:4).eq.'EG93' .or. grid(1:4).eq.'FG03' .or. &
+ grid(1:4).eq.'DG52' .or. grid(1:4).eq.'DG73') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FF' .and. grid(3:3).eq.'3' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'41' .or. grid(3:4).eq.'29')) then; lgvalid=.false.
+ endif
+endif
+
+! Cuba CL,CM,CO,T4
+ else if(callsign(1:2).eq.'CL' .or. callsign(1:2).eq.'CM' .or. callsign(1:2).eq.'CO') then
+ if((grid(1:2).eq.'EL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. grid(1:4).eq.'FK19') lgvalid=.true.
+
+! Canada CF..CK,CY,CZ,VA..VG,VO,VX,VY,XJ..XO
+ else if((callsign(2:2).gt.'E' .and. callsign(2:2).lt.'L').or. callsign(1:2).eq.'CY' .or. callsign(1:2).eq.'CZ') then
+ if((grid(1:2).eq.'CN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FN' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EN' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. grid(1:2).eq.'CO' .or. &
+ (grid(1:2).eq.'GN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ grid(1:2).eq.'FO' .or. grid(1:2).eq.'EO' .or. grid(1:2).eq.'DO' .or. &
+ (grid(1:2).eq.'GO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'DN'.and. grid(4:4).gt.'8' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'CP' .or. grid(1:2).eq.'DP' .or. grid(1:2).eq.'EP' .or. &
+ (grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'96')) .or. &
+ (grid(1:2).eq.'EQ' .and. (grid(3:4).eq.'15' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'24' .or.grid(3:4).eq.'71'.or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'79' .or. grid(3:4).eq.'84' .or. grid(3:4).eq.'86' .or.grid(3:4).eq.'96')).or. &
+ (grid(1:2).eq.'FR' .and. (grid(3:4).eq.'71' .or. grid(3:4).eq.'82')) .or. &
+ (grid(1:2).eq.'FQ' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'12')) .or. grid(1:4).eq.'GN03' .or. &
+ grid(1:4).eq.'FN93' .or. grid(1:4).eq.'ER60' .or. grid(1:4).eq.'DQ10' .or. grid(1:4).eq.'CQ71') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'EO' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'7' .and.grid(4:4).lt.':').or. &
+ (grid(4:4).eq.'7' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9') .or. grid(3:4).eq.'76' .or. grid(3:4).eq.'86')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'8').or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. grid(3:4).eq.'30'.or.grid(3:4).eq.'31'.or. &
+ grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EP' .and. ((grid(4:4).eq.'0' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(4:4).eq.'1' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9') .or. &
+ (grid(4:4).eq.'2' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CN' .and. (grid(3:4).eq.'68' .or. grid(3:4).eq.'98')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. &
+ grid(4:4).lt.'8') .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ endif
+endif
+
+! Portugal, Madeira, Azores CQ..CU
+ else if(callsign(2:2).gt.'P' .and. callsign(2:2).lt.'U') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'IM' .and. grid(3:3).gt.'4' .and. ((grid(3:3).lt.'7' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'12' .or. grid(3:4).eq.'13' .or. grid(3:4).eq.'10' .or. grid(3:4).eq.'20')) .or. &
+ (grid(1:2).eq.'HM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'76'))) lgvalid=.true.
+
+! Uruguay CV..CX
+ else if(callsign(2:2).gt.'U' .and. callsign(2:2).lt.'Y') then
+ if(grid(1:2).eq.'GF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') &
+ lgvalid=.true.
+
+! Bolivia CP
+ else if(callsign(1:2).eq.'CP') then
+ if((grid(1:2).eq.'FH' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FG' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'GH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4').or. &
+ (grid(1:2).eq.'FI' .and. (grid(3:4).eq.'60' .or. grid(3:4).eq.'70')) .or. &
+ (grid(1:2).eq.'GG' .and. (grid(3:4).eq.'09' .or. grid(3:4).eq.'19'))) lgvalid=.true.
+
+! Nauru C2, Andorra C3
+ else if((callsign(1:2).eq.'C2' .and. grid(1:4).eq.'RI39') .or. (callsign(1:2).eq.'C3' .and. grid(1:4).eq.'JN02')) then
+ lgvalid=.true.
+
+! Morocco 5C..5G,CN
+ else if(callsign(1:2).eq.'CN') then
+ if((grid(1:2).eq.'IM' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'69' .or. grid(3:4).eq.'79'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:3).eq.'IM9' .and. (grid(4:4).eq.'0' .or. grid(4:4).eq.'1' .or. grid(4:4).eq.'5')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0' .and. &
+ grid(4:4).lt.'6') .or. (grid(4:4).eq.'1' .or. grid(4:4).eq.'3' .or. grid(4:4).eq.':') .or. &
+ (grid(4:4).eq.'2' .or. grid(4:4).eq.'6' .or. grid(4:4).eq.':') .or. &
+ grid(3:4).eq.'31' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ endif
+endif
+
+! Cyprus 5B,C4,H2,P3
+ else if(callsign(1:2).eq.'C4') then
+ if((grid(1:3).eq.'KM6' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5')) .or. &
+ (grid(1:3).eq.'KM7' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5'))) lgvalid=.true.
+
+ ! The Gambia C5
+ else if(callsign(1:2).eq.'C5' .and. grid(1:2).eq.'IK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. &
+ grid(4:4).eq.'3') then
+ lgvalid=.true.
+
+ ! Bahamas C6
+ else if(callsign(1:2).eq.'C6' .and. grid(1:2).eq.'FL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. &
+ grid(4:4).gt.'1' .and. grid(4:4).lt.'7') then
+ lgvalid=.true.
+
+ ! Mozambique C8,C9
+ else if(callsign(1:2).eq.'C8' .or. callsign(1:2).eq.'C9') then
+ if((grid(1:2).eq.'KG' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KH' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LH' .and. grid(3:3).eq.'1' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':')) lgvalid=.true.
+
+! not valid callsigns 'C'
+ else if(callsign(2:2).eq.'0' .or. callsign(2:2).eq.'1' .or. callsign(2:2).eq.'7') then
+ lwrongcall=.true.; return
+
+ endif ! 'C'
+
+ else if(callsign(1:1).eq.'D') then
+
+! Fed. Rep. of Germany DA..DR, Y2..Y9
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'S') then
+ if((grid(1:2).eq.'JO' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'45')) .or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'IB59') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JO' .and. ((grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'35')) lgvalid=.false.
+endif
+
+! Republic of Korea 6K,6L,6M,6N,D7,D8,D9,DS,DT,HL
+ else if(callsign(1:2).eq.'DS' .or. callsign(1:2).eq.'DT' .or. &
+ (callsign(2:2).gt.'6' .and. callsign(2:2).lt.':')) then
+ if((grid(1:3).eq.'PM3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:3).eq.'PM4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9') .or. &
+ grid(1:4).eq.'PM24' .or. grid(1:4).eq.'PM57' .or. grid(1:4).eq.'GC07') lgvalid=.true. ! DT8A in GC07OS South Shetland Islands
+
+! Philippines 4D,4E,4F,4G,4H,4I,DU,DV,DW,DX,DY,DZ
+ else if(callsign(2:2).gt.'T' .and. callsign(2:2).lt.'[') then
+ if((grid(1:2).eq.'PK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'04')) .or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'OK' .and. grid(3:3).eq.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') .or. &
+ (grid(1:2).eq.'PL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ grid(1:4).eq.'OK70' .or. grid(1:4).eq.'OK71') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PK' .and. ((grid(3:3).eq.'3' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'2' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PJ' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'15')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ endif
+endif
+
+! D0,D1 prefixes in transmitted message, mapping is required to prevent treating it as false decodes
+ else if(callsign(1:2).eq.'D0' .or. callsign(1:2).eq.'D1') then
+ if(grid(1:3).eq.'KN8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':' .or. &
+ grid(1:3).eq.'KN9' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':' .or. &
+ grid(1:4).eq.'LN08' .or. grid(1:4).eq.'LN09') lgvalid=.true.
+
+! Angola D2,D3
+ else if(callsign(1:2).eq.'D2' .or. callsign(1:2).eq.'D3') then
+ if((grid(1:2).eq.'JI' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'JH' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KH' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'01' .or. grid(3:4).eq.'28')) .or. &
+ (grid(1:3).eq.'KI0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:3).eq.'JH5' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5')) lgvalid=.true.
+
+! Cape Verde D4
+ else if(callsign(1:2).eq.'D4' .and. ((grid(1:3).eq.'HK7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:3).eq.'HK8' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7'))) then
+ lgvalid=.true.
+
+! Liberia 5L,5M,6Z,A8,D5,EL
+ else if(callsign(1:2).eq.'D5') then
+ if(grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' .and. &
+ grid(3:4).ne.'67' .and. grid(3:4).ne.'67') lgvalid=.true.
+
+! Comoros D6
+ else if(callsign(1:2).eq.'D6' .and. grid(1:2).eq.'LH' .and. (grid(3:4).eq.'17' .or. grid(3:4).eq.'18' .or. &
+ grid(3:4).eq.'27')) then
+ lgvalid=.true.
+
+ endif ! 'D'
+
+ else if(callsign(1:1).eq.'E') then
+
+! Spain AM..AO,EA..EH
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'I') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4'.and. &
+ grid(3:4).ne.'50') .or. &
+ (grid(1:2).eq.'IM' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'12' .or. grid(3:4).eq.'13' .or. grid(3:4).eq.'75' .or. grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'JN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'20')) .or. &
+ (grid(1:2).eq.'JM' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09' .or.grid(3:4).eq.'19'.or.grid(3:4).eq.'29')).or. &
+ (grid(1:2).eq.'IL' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(4:4).eq.'8' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. grid(3:4).eq.'39'))) lgvalid=.true.
+
+! Ukraine EM..EO,UR..UZ
+ else if(callsign(2:2).gt.'L' .and. callsign(2:2).lt.'P') then
+ if((grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52' .or. grid(3:4).eq.'62')) .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KO' .and. (grid(3:4).eq.'81' .or. grid(3:4).eq.'91')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KN' .and. ((grid(3:3).gt.'0'.and.grid(3:3).lt.'4'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'95' .or. grid(3:4).eq.'96')) then; lgvalid=.false.
+ endif
+endif
+
+! Ireland EI,EJ
+ else if(callsign(1:2).eq.'EI' .or. callsign(1:2).eq.'EJ') then
+ if(grid(1:2).eq.'IO' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'6') &
+ lgvalid=.true.
+
+! Thailand E2,HS
+ else if(callsign(1:2).eq.'E2') then
+ if((grid(1:2).eq.'OK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'9').or. &
+ grid(3:4).eq.'09')) .or. &
+ (grid(1:2).eq.'NK' .and. ((grid(3:3).gt.'8' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'87' .or. grid(3:4).eq.'88'.or. &
+ grid(3:4).eq.'89')) .or. &
+ (grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'88' .or. grid(3:4).eq.'89')) .or. &
+ (grid(1:2).eq.'OJ' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or.grid(3:4).eq.'16')).or. &
+ grid(1:4).eq.'NL90' .or. grid(1:4).eq.'OL00') lgvalid=.true.
+
+! Eritrea E3
+ else if(callsign(1:2).eq.'E3') then
+ if((grid(1:2).eq.'KK' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7')) &
+ lgvalid=.true.
+
+! Palestine E4
+ else if(callsign(1:2).eq.'E4' .and. (grid(1:4).eq.'KM71' .or. grid(1:4).eq.'KM72')) then
+ lgvalid=.true.
+
+! North Cook and South Cook Islands E5
+ else if(callsign(1:2).eq.'E5') then
+ if((grid(1:2).eq.'BH' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ (grid(1:2).eq.'BG' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09'.or.grid(3:4).eq.'18'.or.grid(3:4).eq.'19')) .or. &
+ (grid(1:2).eq.'AH' .and. (grid(3:4).eq.'78' .or. grid(3:4).eq.'79'.or.grid(3:4).eq.'81'.or.grid(3:4).eq.'86' .or. &
+ grid(3:4).eq.'99')) .or. &
+ (grid(1:2).eq.'BI' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01'.or.grid(3:4).eq.'10'.or.grid(3:4).eq.'11'))) &
+ lgvalid=.true.
+
+! Niue E6
+ else if(callsign(1:2).eq.'E6') then
+ if(grid(1:4).eq.'AH50' .or. grid(1:4).eq.'AH51') lgvalid=.true.
+
+! Bosnia-Herzegovina E7
+ else if(callsign(1:2).eq.'E7') then
+ if(grid(1:2).eq.'JN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'6' .and. &
+ grid(3:4).ne.'72' .and. grid(3:4).ne.'73') lgvalid=.true.
+
+! Belarus EU,EV,EW
+ else if(callsign(2:2).gt.'T' .and. callsign(2:2).lt.'X') then
+ if(grid(1:2).eq.'KO' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'7') &
+ lgvalid=.true.
+
+! Estonia ES
+ else if(callsign(1:2).eq.'ES') then
+ if((grid(1:2).eq.'KO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'KO49') lgvalid=.true.
+
+! Moldova ER
+ else if(callsign(1:2).eq.'ER') then
+ if((grid(1:2).eq.'KN' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9').or. &
+ grid(1:4).eq.'KN56') lgvalid=.true.
+
+! Armenia EK
+ else if(callsign(1:2).eq.'EK') then
+ if((grid(1:2).eq.'LN' .and. (grid(3:4).eq.'10' .or. grid(3:4).eq.'11' .or. grid(3:4).eq.'20' .or. &
+ grid(3:4).eq.'21')) .or. &
+ (grid(1:2).eq.'LM' .and. (grid(3:4).eq.'29' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'38'))) lgvalid=.true.
+
+! Kyrgyzstan EX
+ else if(callsign(1:2).eq.'EX') then
+ if((grid(1:2).eq.'MN' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4').or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+! Tajikistan EY
+ else if(callsign(1:2).eq.'EY') then
+ if((grid(1:2).eq.'MM' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'MN' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'50'))) lgvalid=.true.
+
+! Turkmenistan EZ
+ else if(callsign(1:2).eq.'EZ') then
+ if((grid(1:2).eq.'LM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'MN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2')) &
+ lgvalid=.true.
+
+! Liberia 5L,5M,6Z,A8,D5,EL
+ else if(callsign(1:2).eq.'EL') then
+ if(grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' .and. &
+ grid(3:4).ne.'67' .and. grid(3:4).ne.'67') lgvalid=.true.
+
+! Iran 9B..9D,EP,EQ
+ else if(callsign(1:2).eq.'EP' .or. callsign(1:2).eq.'EQ') then
+ if((grid(1:2).eq.'LM' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LL' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'49' .or. grid(3:4).eq.'75' .or. grid(3:4).eq.'85' .or. grid(3:4).eq.'95')) .or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'15' .and. grid(3:4).ne.'19') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).eq.'0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7')) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'LM' .and. ((grid(3:3).eq.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4') .or. &
+ (grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'78' .and. grid(3:4).ne.'88'))) lgvalid=.false.
+endif
+
+! Ethiopia 9E,9F,ET
+ else if(callsign(1:2).eq.'ET') then
+ if((grid(1:2).eq.'LJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'KJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5')) &
+ lgvalid=.true.
+
+! not valid callsigns E0 E1 E8 E9
+ else if(callsign(2:2).eq.'0' .or. callsign(2:2).eq.'1' .or. callsign(2:2).eq.'8' .or. callsign(2:2).eq.'9') then
+ lwrongcall=.true.; return
+
+ endif ! 'E'
+
+ else if(callsign(1:1).eq.'F') then
+
+! France F,FA..FF,FI,FL,FN,FQ,FU,FV,FX,FZ,HW..HY,TH,TM,TP,TQ,TV
+ if((callsign(2:2).gt.'/' .and. callsign(2:2).lt.':') .or. (callsign(2:2).gt.'@' .and. callsign(2:2).lt.'G') .or. &
+ callsign(2:2).eq.'I' .or. callsign(2:2).eq.'L' .or. callsign(2:2).eq.'N' .or. callsign(2:2).eq.'Q' .or. &
+ callsign(2:2).eq.'U' .or. callsign(2:2).eq.'V' .or. callsign(2:2).eq.'X' .or. callsign(2:2).eq.'Z') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'IN7' .and. (grid(4:4).eq.'7' .or. grid(4:4).eq.'8')) .or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'JN4' .and. (grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ grid(1:4).eq.'JN02' .or. grid(1:4).eq.'JN12' .or. grid(1:4).eq.'IN92' .or. &
+ (grid(1:2).eq.'JO' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'10' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'11'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'IN' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) lgvalid=.false.
+endif
+
+! Martinique FM,TO
+ else if(callsign(1:2).eq.'FM' .and. grid(1:4).eq.'FK94') then
+ lgvalid=.true.
+
+! Guadeloupe FG,TO
+ else if(callsign(1:2).eq.'FG') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'96' .or. grid(3:4).eq.'95')) lgvalid=.true.
+
+! St. Pierre & Miquelon FP
+ else if(callsign(1:2).eq.'FP') then
+ if(grid(1:2).eq.'GN' .and. (grid(3:4).eq.'16' .or. grid(3:4).eq.'17')) lgvalid=.true.
+
+! St. Martin FS,TO
+ else if(callsign(1:2).eq.'FS' .and. grid(1:4).eq.'FK88') then
+ lgvalid=.true.
+
+! St. Barthelemy FJ,TO
+ else if(callsign(1:2).eq.'FJ' .and. grid(1:4).eq.'FK87') then
+ lgvalid=.true.
+
+! French Guiana FY
+ else if(callsign(1:2).eq.'FY') then
+ if(grid(1:2).eq.'GJ' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'6') &
+ lgvalid=.true.
+
+! Reunion Island FR,TO
+ else if(callsign(1:2).eq.'FR') then
+ if(grid(1:2).eq.'LG' .and. (grid(3:4).eq.'79' .or. grid(3:4).eq.'78')) lgvalid=.true.
+
+! New Caledonia FK
+ else if(callsign(1:2).eq.'FK') then
+ if((grid(1:2).eq.'RG' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'RH' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'RG' .and. (grid(3:4).eq.'19' .or. grid(3:4).eq.'57' .or. grid(3:4).eq.'67'))) lgvalid=.true.
+
+! Chesterfield Islands FK,TX
+ else if(callsign(1:2).eq.'FK') then
+ if((grid(1:2).eq.'QH' .and. (grid(3:4).eq.'90' .or. grid(3:4).eq.'91')) .or. grid(1:4).eq.'QG98') lgvalid=.true.
+
+! Mayotte FH
+ else if(callsign(1:2).eq.'FH') then
+ if(grid(1:2).eq.'LH' .and. (grid(3:4).eq.'27' .or. grid(3:4).eq.'26')) lgvalid=.true.
+
+! Glorioso, Juan de Nova, Europa, Tromelin, Crozet, Kerguelen, Amsterdam & St. Paul Islands FT
+ else if(callsign(1:2).eq.'FT') then
+ if((grid(1:2).eq.'LH' .and. (grid(3:4).eq.'38' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'74')) .or. &
+ (grid(1:2).eq.'LE' .and. (grid(3:4).eq.'53' .or. grid(3:4).eq.'54' .or. grid(3:4).eq.'63')) .or. &
+ (grid(1:2).eq.'ME' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'41' .or. grid(3:4).eq.'50')) .or. &
+ (grid(1:2).eq.'MF' .and. (grid(3:4).eq.'81' .or. grid(3:4).eq.'82')) .or. &
+ grid(1:4).eq.'LG07' .or. grid(1:4).eq.'KG98') lgvalid=.true.
+
+! French Polynesia, Austral, Marquesas, Clipperton Islands FO,TX
+ else if(callsign(1:2).eq.'FO') then
+ if((grid(1:2).eq.'BH' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'BG' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'BI9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'CI' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) .or. &
+ grid(1:4).eq.'CH09' .or. grid(1:4).eq.'DK50') lgvalid=.true.
+
+! Wallis & Futuna Islands FW,TW
+ else if(callsign(1:2).eq.'FW') then
+ if(grid(1:2).eq.'AH' .and. (grid(3:4).eq.'05' .or. grid(3:4).eq.'16')) lgvalid=.true.
+
+ endif ! 'F'
+
+! UK GB,GX / 2E,G,M / 2D,GD,GT,MD,MT / 2I,GI,GN,MI,MN / 2J,GH,GJ,MH,MJ / 2A,2M,GM,GS,MA,MM,MS / 2U,GP,GU,MP,MU / 2W,GC,GW,MC,MW
+ else if(callsign(1:1).eq.'G') then
+ if((grid(1:2).eq.'IO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'JO0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(1:4).eq.'IP90' .or. grid(1:4).eq.'IN69' .or. grid(1:4).eq.'IN89' .or. grid(1:4).eq.'IO37') lgvalid=.true.
+
+if(lgvalid .and. grid(1:2).eq.'IO') then
+ if((grid(1:3).eq.'IO5' .and. grid(4:4).ne.'4' .and. grid(4:4).ne.'7') .or. &
+ (grid(1:3).eq.'IO6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'96' .or. grid(3:4).eq.'98') lgvalid=.false.
+endif
+
+ else if(callsign(1:1).eq.'H') then
+
+! Hungary HA,HG
+ if(callsign(1:2).eq.'HA' .or. callsign(1:2).eq.'HG') then
+ if((grid(1:2).eq.'JN' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.'9' .and. &
+ grid(3:4).ne.'16')) lgvalid=.true.
+
+! Switzerland, Liechtenstein HB,HE
+ else if(callsign(1:2).eq.'HB' .or. callsign(1:2).eq.'HE') then
+ if(((grid(1:3).eq.'JN3' .or. grid(1:3).eq.'JN4') .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'8') .or. &
+ grid(1:4).eq.'JN56') lgvalid=.true.
+
+! Thailand E2,HS
+ else if(callsign(1:2).eq.'HS') then
+ if((grid(1:2).eq.'OK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'9').or. &
+ grid(3:4).eq.'09')) .or. &
+ (grid(1:2).eq.'NK' .and. ((grid(3:3).gt.'8' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'87' .or. grid(3:4).eq.'88'.or. &
+ grid(3:4).eq.'89')) .or. &
+ (grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'88' .or. grid(3:4).eq.'89')) .or. &
+ (grid(1:2).eq.'OJ' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or.grid(3:4).eq.'16')).or. &
+ grid(1:4).eq.'NL90' .or. grid(1:4).eq.'OL00') lgvalid=.true.
+
+! Cyprus 5B,C4,H2,P3
+ else if(callsign(1:2).eq.'H2') then
+ if((grid(1:3).eq.'KM6' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5')) .or. &
+ (grid(1:3).eq.'KM7' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5'))) lgvalid=.true.
+
+! Poland 3Z,HF,SN..SR
+ else if(callsign(1:2).eq.'HF') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'20')) .or. &
+ grid(1:4).eq.'KN09' .or. grid(1:4).eq.'KN19' .or. grid(1:4).eq.'KO20' .or. grid(1:4).eq.'JN99' .or. &
+ grid(1:4).eq.'JN89') lgvalid=.true.
+
+! Nicaragua H6,H7,HT,YN
+ else if(callsign(1:2).eq.'H6' .or. callsign(1:2).eq.'H7' .or. callsign(1:2).eq.'HT') then
+ if(grid(1:2).eq.'EK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') &
+ lgvalid=.true.
+
+! Ecuador HC HD
+ else if(callsign(1:2).eq.'HC' .or. callsign(1:2).eq.'HD') then
+ if((grid(1:2).eq.'FI' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'05' .or. grid(3:4).eq.'06')) .or. &
+ (grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3'.and.grid(4:4).eq.'0').or.grid(3:4).eq.'01')).or. &
+ (grid(1:2).eq.'EI' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'49' .or. grid(3:4).eq.'59' .or. grid(3:4).eq.'48' .or. grid(3:4).eq.'58')) .or. &
+ (grid(1:2).eq.'EJ' .and. (grid(3:4).eq.'90' .or. grid(3:4).eq.'40'))) lgvalid=.true.
+
+! Haiti 4V,HH
+ else if(callsign(1:2).eq.'HH') then
+ if((grid(1:2).eq.'FK' .and. (grid(3:4).eq.'38' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'48' .or. &
+ grid(3:4).eq.'49')) .or. grid(1:4).eq.'FL30') lgvalid=.true.
+
+! Dominican Republic HI
+ else if(callsign(1:2).eq.'HI') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'58' .or. &
+ grid(3:4).eq.'59' .or. grid(3:4).eq.'47')) lgvalid=.true.
+
+! Republic of Korea 6K,6L,6M,6N,D7,D8,D9,DS,DT,HL
+ else if(callsign(1:2).eq.'HL') then
+ if((grid(1:3).eq.'PM3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:3).eq.'PM4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9') .or. &
+ grid(1:4).eq.'PM24' .or. grid(1:4).eq.'PM57' .or. grid(1:4).eq.'GC07') lgvalid=.true. ! DT8A in GC07OS South Shetland Islands
+
+! Colombia 5J,5K,HJ,HK
+ else if(callsign(1:2).eq.'HK' .or. callsign(1:2).eq.'HJ') then
+ if((grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'7') .or. &
+ grid(3:4).eq.'01' .or. grid(3:4).eq.'02' .or. grid(3:4).eq.'03')) .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3' .and. &
+ grid(3:4).ne.'22') .or. &
+ (grid(1:2).eq.'FI' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'6' .and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'45' .or. grid(3:4).eq.'55' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'56') .and.grid(3:4).ne.'27').or. &
+ (grid(1:2).eq.'EJ' .and. (grid(3:4).eq.'93' .or. grid(3:4).eq.'94')) .or. grid(1:4).eq.'EK92') lgvalid=.true.
+
+! Saudi Arabia 7Z,8Z,HZ
+ else if(callsign(1:2).eq.'HZ') then
+ if((grid(1:2).eq.'LL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8').or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'5' .and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ (grid(1:2).eq.'KM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KM92') lgvalid=.true.
+
+! Panama 3E,3F,H3,H8,H9,HO,HP
+ else if(callsign(2:2).eq.'P' .or. callsign(2:2).eq.'3' .or. callsign(2:2).eq.'8' .or. &
+ callsign(2:2).eq.'9' .or. callsign(2:2).eq.'O') then
+ if((grid(1:2).eq.'FJ' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09' .or. grid(3:4).eq.'17' .or. &
+ grid(3:4).eq.'18')) .or. &
+ (grid(1:2).eq.'EJ' .and. (grid(3:4).eq.'88' .or. grid(3:4).eq.'89' .or. grid(3:4).eq.'97' .or. &
+ grid(3:4).eq.'98' .or. grid(3:4).eq.'99'))) lgvalid=.true.
+
+! Honduras HQ,HR
+ else if(callsign(2:2).eq.'R' .or. callsign(2:2).eq.'Q') then
+ if(grid(1:2).eq.'EK' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'2' .and.grid(4:4).lt.'7'.and. &
+ grid(3:4).ne.'56' .and. grid(3:4).ne.'83') lgvalid=.true.
+
+! Iraq HN,YI
+ else if(callsign(1:2).eq.'HN') then
+ if((grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'KM' .and.(grid(3:4).eq.'92' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:2).eq.'LL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+! El Salvador HU,YS
+ else if(callsign(1:2).eq.'HU') then
+ if(grid(1:2).eq.'EK' .and. (grid(3:4).eq.'53' .or. grid(3:4).eq.'54' .or. grid(3:4).eq.'63' .or. grid(3:4).eq.'43')) &
+ lgvalid=.true.
+
+! South Africa H5,S4,S8,V9,ZR,ZS,ZT,ZU
+ else if(callsign(1:2).eq.'H5') then
+ if((grid(1:2).eq.'KG' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4'))) .or. &
+ (grid(1:2).eq.'KF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'JF' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'85') .or. &
+ (grid(1:2).eq.'JG' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KE83' .or. grid(1:4).eq.'KE93') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KF' .and. ((grid(4:4).eq.'5' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. grid(3:4).eq.'57')) lgvalid=.false.
+endif
+
+! France F,FA..FF,FI,FL,FN,FQ,FU,FV,FX,FZ,HW..HY,TH,TM,TP,TQ,TV
+ else if(callsign(2:2).gt.'V' .and. callsign(2:2).lt.'Z') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'IN7' .and. (grid(4:4).eq.'7' .or. grid(4:4).eq.'8')) .or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'JN4' .and. (grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ grid(1:4).eq.'JN02' .or. grid(1:4).eq.'JN12' .or. grid(1:4).eq.'IN92' .or. &
+ (grid(1:2).eq.'JO' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'10' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'11'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'IN' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) lgvalid=.false.
+endif
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'H1') then
+ lwrongcall=.true.; return
+
+ endif ! 'H'
+
+! Italy, Sardinia I
+ else if(callsign(1:1).eq.'I') then
+ if((grid(1:2).eq.'JN' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'40' .or. grid(3:4).eq.'41')) .or. &
+ (grid(1:2).eq.'JM' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'65' .or. grid(3:4).eq.'56'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JM' .and. (grid(3:4).eq.'69' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'96' .or. grid(3:4).eq.'97' .or. &
+ grid(3:4).eq.'98')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'JN' .and. &
+ ((grid(3:3).eq.'7' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'8' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'9' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'50')) then; lgvalid=.false.
+ endif
+endif
+
+ else if(callsign(1:1).eq.'J') then
+
+! Japan 7J..7N,8J..8N,JA,JE..JS
+ if(callsign(1:2).eq.'JA' .or. (callsign(2:2).gt.'D' .and. callsign(2:2).lt.'T')) then
+ if((grid(1:2).eq.'PM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'QM0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'QN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:3).eq.'PN9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'QM19' .or. grid(1:4).eq.'KC90') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and.grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3'.and.grid(3:4).ne.'62').or. &
+ grid(3:4).eq.'45' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'55' .or. grid(3:4).eq.'56' .or.grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'89')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PL'.and.((grid(3:3).gt.'0'.and.grid(3:3).lt.'3'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'38' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'57' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'QN'.and.((grid(3:3).eq.'2'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'1'.or.grid(4:4).eq.'5')).or. &
+ grid(3:4).eq.'10')) then; lgvalid=.false.
+ endif
+endif
+
+! Greece J4,SV..SZ
+ else if(callsign(1:2).eq.'J4') then
+ if((grid(1:2).eq.'KM' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'46' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'14').and.grid(3:4).ne.'05').or. &
+ grid(1:4).eq.'JM99' .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. (grid(4:4).eq.'0' .or. grid(4:4).eq.'1'))) &
+ lgvalid=.true.
+
+! Djibouti J2
+ else if(callsign(1:2).eq.'J2') then
+ if(grid(1:2).eq.'LK' .and. (grid(3:4).eq.'01' .or. grid(3:4).eq.'11' .or. grid(3:4).eq.'12')) lgvalid=.true.
+
+! Grenada J3
+ else if(callsign(1:2).eq.'J3') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'92' .or. grid(3:4).eq.'91')) lgvalid=.true.
+
+! Guinea-Bissau J5
+ else if(callsign(1:2).eq.'J5') then
+ if(grid(1:2).eq.'IK' .and. (grid(3:4).eq.'21' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'11' .or. &
+ grid(3:4).eq.'12' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'20')) lgvalid=.true.
+
+! St. Lucia J6
+ else if(callsign(1:2).eq.'J6') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'93' .or. grid(3:4).eq.'94')) lgvalid=.true.
+
+! Dominica J7
+ else if(callsign(1:2).eq.'J7' .and. grid(1:4).eq.'FK95') then
+ lgvalid=.true.
+
+! St. Vincent J8
+ else if(callsign(1:2).eq.'J8') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'93' .or. grid(3:4).eq.'92')) lgvalid=.true.
+
+! Ogasawara and Minami Torishima JD1
+ else if(callsign(1:3).eq.'JD1') then
+ if(grid(1:2).eq.'QL' .and. (grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. grid(3:4).eq.'16' .or. grid(3:4).eq.'17')) &
+ lgvalid=.true.
+
+! Mongolia JT..JV
+ else if(callsign(2:2).eq.'T' .or. callsign(2:2).eq.'U' .or. callsign(2:2).eq.'V') then
+ if((grid(1:2).eq.'ON' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'NN' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'NO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'OO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'OO' .and. (grid(3:4).eq.'60' .or. grid(3:4).eq.'70'))) lgvalid=.true.
+
+! Svalbard, Bear Island JW
+ else if(callsign(1:2).eq.'JW') then
+ if((grid(1:2).eq.'JQ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KQ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JR' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0') .or. &
+ (grid(1:2).eq.'KR' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'0') .or. &
+ grid(1:4).eq.'JQ94') lgvalid=.true.
+
+! Jan Mayen JX
+ else if(callsign(1:2).eq.'JX') then
+ if(grid(1:2).eq.'IQ' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'61')) lgvalid=.true.
+
+! Jordan JY
+ else if(callsign(1:2).eq.'JY') then
+ if((grid(1:2).eq.'KM' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4').or. &
+ (grid(1:2).eq.'KL' .and. (grid(3:4).eq.'79' .or. grid(3:4).eq.'89'))) lgvalid=.true.
+
+! not valid callsigns
+ else if(callsign(2:2).eq.'B' .or. callsign(2:2).eq.'C' .or. callsign(2:2).eq.'1' .or. &
+ callsign(2:2).eq.'9' .or. callsign(2:2).eq.'Z' .or. &
+ (callsign(1:2).eq.'JD' .and. callsign(3:3).gt.'1' .and. callsign(3:3).lt.':')) then
+ lwrongcall=.true.; return
+
+ endif ! 'J'
+
+! USA AA..AL,K,N,W
+ else if(callsign(1:1).eq.'K') then
+ if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':' .and. callsign(3:3).gt.'/' .and. callsign(3:3).lt.':') return ! checkcall
+ if((grid(1:2).eq.'FM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EL' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'DL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'EM' .or. grid(1:2).eq.'DM' .or. grid(1:2).eq.'EN' .or. &
+ (grid(1:2).eq.'CM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'DN' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. &
+ grid(1:2).eq.'BP' .or. &
+ (grid(1:2).eq.'BO' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AP' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ grid(1:4).eq.'FK28' .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'BL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'BK' .and. (grid(3:4).eq.'19' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'AL' .and. (grid(3:4).eq.'91' .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. &
+ grid(3:4).eq.'27' .or. grid(3:4).eq.'36' .or. grid(3:4).eq.'45' .or. grid(3:4).eq.'64' .or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:3).eq.'QK2' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'RO' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3').or. &
+ grid(3:4).eq.'63')) .or. &
+ grid(1:4).eq.'AP30' .or. grid(1:4).eq.'QK36' .or. grid(1:4).eq.'QL20' .or. grid(1:4).eq.'RK39' .or. &
+ grid(1:4).eq.'AK56' .or. grid(1:4).eq.'AH48' .or. grid(1:4).eq.'JA00' .or. grid(1:4).eq.'RB32' .or. &
+ grid(1:4).eq.'CP00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FM' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'24')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' &
+ .and. grid(3:4).ne.'28'.and. grid(3:4).ne.'58') .or. grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. &
+ grid(3:4).eq.'14')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DL' .and. (grid(3:4).eq.'78' .or. grid(3:4).eq.'88')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EN' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ ((grid(3:3).eq.'8' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9' .and. grid(3:3).ne.'2'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CM' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FN' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. grid(3:4).eq.'15' .or. grid(3:4).eq.'52')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'BO' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'3'.and.grid(4:4).lt.'9').or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AP' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(4:4).gt.'3' .and. grid(4:4).lt.':'))) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'63' .or. &
+ grid(3:4).eq.'67' .or. grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AO' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'2' .and. grid(4:4).lt.'7') .or. &
+ grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':' .and. grid(4:4).ne.'6') .or. &
+ ((grid(3:3).eq.'6' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'62' .or. grid(3:4).eq.'97' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'87' .or.grid(3:4).eq.'31')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'BL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21' .or. &
+ grid(3:4).eq.'22')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'RO' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'71')) then; lgvalid=.false.
+ endif
+endif
+
+ endif ! end of block A..K
+
+2 if(callsign(1:1).eq.'L') then
+
+! Norway LA..LN
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'O') then
+ if((grid(1:2).eq.'JO' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'37')) .or. &
+ (grid(1:2).eq.'JP' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'KP' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KQ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ grid(1:4).eq.'JQ90') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JP' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ (grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ grid(3:4).eq.'23' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'58' .or. &
+ grid(3:4).eq.'59' .or. grid(3:4).eq.'69' .or. grid(3:4).eq.'97')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. grid(4:4).eq.'8' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6') then; lgvalid=.false.
+ else if(grid(1:2).eq.'KQ' .and. (grid(3:4).eq.'01' .or. grid(3:4).eq.'51')) then; lgvalid=.false.
+ endif
+endif
+
+! Argentina AY,AZ, L1..L9, LO..LW
+ else if(callsign(2:2).gt.'N' .and. callsign(2:2).lt.'X') then
+ if((grid(1:2).eq.'GF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FF' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FG' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'GG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'9') .or. &
+ (grid(1:2).eq.'FD' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'GC07' .or. grid(1:4).eq.'GC16') lgvalid=.true. ! LU1ZB in GC16
+
+if(lgvalid) then
+ if(grid(1:2).eq.'GF' .and. (grid(3:4).eq.'16' .or. grid(3:4).eq.'17')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FG' .and. (grid(3:4).eq.'56' .or. grid(3:4).eq.'57')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GG' .and. (grid(3:4).eq.'20' .or. grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. &
+ grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. ((grid(3:3).eq.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'70' .or. grid(3:4).eq.'73')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'2'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':'))) then; lgvalid=.false.
+ endif
+endif
+
+! Luxemburg LX
+ else if(callsign(1:2).eq.'LX') then
+ if((grid(1:2).eq.'JN' .and. (grid(3:4).eq.'29' .or. grid(3:4).eq.'39')) .or. &
+ (grid(1:2).eq.'JO' .and. (grid(3:4).eq.'20' .or. grid(3:4).eq.'30'))) lgvalid=.true.
+
+! Lithuania LY
+ else if(callsign(1:2).eq.'LY') then
+ if(grid(1:2).eq.'KO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7') &
+ lgvalid=.true.
+
+! Bulgaria LZ
+ else if(callsign(1:2).eq.'LZ') then
+ if(grid(1:2).eq.'KN' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'5') &
+ lgvalid=.true.
+
+! Argentina AY,AZ, L1..L9, LO..LW
+ else if(callsign(2:2).gt.'0' .and. callsign(2:2).lt.':') then
+ if((grid(1:2).eq.'GF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FF' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FG' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'GG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'9') .or. &
+ (grid(1:2).eq.'FD' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'GC07' .or. grid(1:4).eq.'GC16') lgvalid=.true. ! LU1ZB in GC16
+
+if(lgvalid) then
+ if(grid(1:2).eq.'GF' .and. (grid(3:4).eq.'16' .or. grid(3:4).eq.'17')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FG' .and. (grid(3:4).eq.'56' .or. grid(3:4).eq.'57')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GG' .and. (grid(3:4).eq.'20' .or. grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. &
+ grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. ((grid(3:3).eq.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'70' .or. grid(3:4).eq.'73')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'2'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':'))) then; lgvalid=.false.
+ endif
+endif
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'L0') then
+ lwrongcall=.true.; return
+
+ endif ! 'L'
+
+! UK GB,GX / 2E,G,M / 2D,GD,GT,MD,MT / 2I,GI,GN,MI,MN / 2J,GH,GJ,MH,MJ / 2A,2M,GM,GS,MA,MM,MS / 2U,GP,GU,MP,MU / 2W,GC,GW,MC,MW
+ else if(callsign(1:1).eq.'M') then
+ if((grid(1:2).eq.'IO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'JO0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(1:4).eq.'IP90' .or. grid(1:4).eq.'IN69' .or. grid(1:4).eq.'IN89' .or. grid(1:4).eq.'IO37') lgvalid=.true.
+
+if(lgvalid .and. grid(1:2).eq.'IO') then
+ if((grid(1:3).eq.'IO5' .and. grid(4:4).ne.'4' .and. grid(4:4).ne.'7') .or. &
+ (grid(1:3).eq.'IO6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'96' .or. grid(3:4).eq.'98') lgvalid=.false.
+endif
+
+! USA AA..AL,K,N,W
+ else if(callsign(1:1).eq.'N') then
+ if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':' .and. callsign(3:3).gt.'/' .and. callsign(3:3).lt.':') return ! checkcall
+ if((grid(1:2).eq.'FM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EL' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'DL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'EM' .or. grid(1:2).eq.'DM' .or. grid(1:2).eq.'EN' .or. &
+ (grid(1:2).eq.'CM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'DN' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. &
+ grid(1:2).eq.'BP' .or. &
+ (grid(1:2).eq.'BO' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AP' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ grid(1:4).eq.'FK28' .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'BL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'BK' .and. (grid(3:4).eq.'19' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'AL' .and. (grid(3:4).eq.'91' .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. &
+ grid(3:4).eq.'27' .or. grid(3:4).eq.'36' .or. grid(3:4).eq.'45' .or. grid(3:4).eq.'64' .or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:3).eq.'QK2' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'RO' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3').or. &
+ grid(3:4).eq.'63')) .or. &
+ grid(1:4).eq.'AP30' .or. grid(1:4).eq.'QK36' .or. grid(1:4).eq.'QL20' .or. grid(1:4).eq.'RK39' .or. &
+ grid(1:4).eq.'AK56' .or. grid(1:4).eq.'AH48' .or. grid(1:4).eq.'JA00' .or. grid(1:4).eq.'RB32' .or. &
+ grid(1:4).eq.'CP00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FM' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'24')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' &
+ .and. grid(3:4).ne.'28'.and. grid(3:4).ne.'58') .or. grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. &
+ grid(3:4).eq.'14')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DL' .and. (grid(3:4).eq.'78' .or. grid(3:4).eq.'88')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EN' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ ((grid(3:3).eq.'8' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9' .and. grid(3:3).ne.'2'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CM' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FN' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. grid(3:4).eq.'15' .or. grid(3:4).eq.'52')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'BO' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'3'.and.grid(4:4).lt.'9').or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AP' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(4:4).gt.'3' .and. grid(4:4).lt.':'))) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'63' .or. &
+ grid(3:4).eq.'67' .or. grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AO' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'2' .and. grid(4:4).lt.'7') .or. &
+ grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':' .and. grid(4:4).ne.'6') .or. &
+ ((grid(3:3).eq.'6' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'62' .or. grid(3:4).eq.'97' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'87' .or.grid(3:4).eq.'31')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'BL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21' .or. &
+ grid(3:4).eq.'22')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'RO' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'71')) then; lgvalid=.false.
+ endif
+endif
+
+ else if(callsign(1:1).eq.'O') then
+
+! Finland OF..OJ
+ if(callsign(2:2).gt.'E' .and. callsign(2:2).lt.'K') then
+ if((grid(1:2).eq.'KP' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6') .or. &
+ grid(1:4).eq.'JP90' .or. grid(1:4).eq.'KO09' .or. grid(1:4).eq.'KO19' .or. grid(1:4).eq.'KQ30') lgvalid=.true.
+
+! Belgium ON..OT
+ else if(callsign(2:2).gt.'M' .and. callsign(2:2).lt.'U') then
+ if((grid(1:2).eq.'JO' .and. (grid(3:4).eq.'10' .or. grid(3:4).eq.'11' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'21' .or. &
+ grid(3:4).eq.'30')) .or. grid(1:4).eq.'JN29') lgvalid=.true.
+
+! Austria OE
+ else if(callsign(1:2).eq.'OE') then
+ if(grid(1:2).eq.'JN' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.'9') &
+ lgvalid=.true.
+
+! Czech Republic OK,OL
+ else if(callsign(2:2).eq.'K' .or. callsign(2:2).eq.'L') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0').or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'JO71') lgvalid=.true.
+
+! Slovak Republic OM
+ else if(callsign(1:2).eq.'OM') then
+ if((grid(1:2).eq.'JN' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Denmark 5P,5Q,OU,OV,OZ
+ else if(callsign(2:2).eq.'Z' .or. callsign(2:2).eq.'U' .or. callsign(2:2).eq.'V') then
+ if(grid(1:2).eq.'JO' .and. &
+ ((grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'75' .or. grid(3:4).eq.'76')) lgvalid=.true.
+
+! Lebanon OD
+ else if(callsign(1:2).eq.'OD') then
+ if(grid(1:2).eq.'KM' .and. (grid(3:4).eq.'73' .or. grid(3:4).eq.'74' .or. grid(3:4).eq.'84')) lgvalid=.true.
+
+! Peru 4T,OA..OC
+ else if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'D') then
+ if((grid(1:2).eq.'FH' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:3).eq.'EI9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'7')) lgvalid=.true.
+
+! Greenland OX,XP
+ else if(callsign(1:2).eq.'OX' .or. callsign(1:2).eq.'XP') then
+ if((grid(1:2).eq.'GP' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'HP' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'HQ90' .or. &
+ (grid(1:2).eq.'GQ' .and. (grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'41' .or.grid(3:4).eq.'22'.or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'12')) .or. &
+ (grid(1:2).eq.'FQ' .and. (grid(3:4).eq.'76' .or. grid(3:4).eq.'67' .or. grid(3:4).eq.'57' .or.grid(3:4).eq.'56'.or. &
+ grid(3:4).eq.'38'))) lgvalid=.true.
+
+! not valid callsigns O0..O9
+ else if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':') then
+ lwrongcall=.true.; return
+
+ endif ! 'O'
+
+ else if(callsign(1:1).eq.'P') then
+
+! Netherlands PA..PI
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'J') then
+ if(((grid(1:3).eq.'JO2' .or. grid(1:3).eq.'JO3') .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(1:4).eq.'JO11') lgvalid=.true.
+
+! Brazil PP..PY, ZV..ZZ
+ else if(callsign(1:1).eq.'P' .and. callsign(2:2).gt.'O' .and. callsign(2:2).lt.'Z') then
+ if((grid(1:2).eq.'GG' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'09')) .or. &
+ (grid(1:2).eq.'HI' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6'.and. &
+ grid(3:4).ne.'25') .or. grid(3:4).eq.'06' .or. grid(3:4).eq.'07' .or. grid(3:4).eq.'36')) .or. &
+ (grid(1:2).eq.'HH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. &
+ (grid(1:2).eq.'GH' .and. grid(3:4).ne.'01') .or. grid(1:2).eq.'GI' .or. &
+ (grid(1:2).eq.'GF' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'36')) .or. &
+ (grid(1:2).eq.'GJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4').or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'44')) .or. &
+ (grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'95')) .or. &
+ (grid(1:2).eq.'FI' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'93' .or. grid(3:4).eq.'94' .or. grid(3:4).eq.'95')) .or. &
+ grid(1:4).eq.'HG59' .or. grid(1:4).eq.'HJ50') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'GG' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'6' .and. grid(3:4).ne.'64' .and. grid(3:4).ne.'65') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'HH' .and. (grid(3:3).eq.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GI' .and. ((grid(3:3).gt.'7'.and.grid(3:3).lt.':'.and.grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GF' .and. (grid(3:4).eq.'17' .or. grid(3:4).eq.'27')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GJ' .and. (grid(3:4).eq.'13' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'52' .or. &
+ grid(3:4).eq.'53')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FJ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'FI' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'5'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'76' .or. grid(3:4).eq.'68')) then; lgvalid=.false.
+ endif
+endif
+
+! Papua New Guinea P2
+ else if(callsign(1:2).eq.'P2') then
+ if((grid(1:2).eq.'QI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or.&
+ (grid(1:2).eq.'QH' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Cyprus 5B,C4,H2,P3
+ else if(callsign(1:2).eq.'P3') then
+ if((grid(1:3).eq.'KM6' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5')) .or. &
+ (grid(1:3).eq.'KM7' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5'))) lgvalid=.true.
+
+! Aruba P4
+ else if(callsign(1:2).eq.'P4' .and. (grid(1:4).eq.'FK42' .or. grid(1:4).eq.'FK52')) then
+ lgvalid=.true.
+
+! DPR of Korea P5..P9
+ else if(callsign(2:2).gt.'4' .and. callsign(2:2).lt.':') then
+ if((grid(1:2).eq.'PM' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or.&
+ (grid(1:2).eq.'PN' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3')) &
+ lgvalid=.true.
+
+! Curacao, Bonaire, Saba & St. Eustatius, Sint Maarten PJ
+ else if(callsign(1:2).eq.'PJ' .and. &
+ ((callsign(3:3).eq.'2' .or. callsign(3:3).eq.'4') .and. grid(1:4).eq.'FK52') .or. &
+ ((callsign(3:3).eq.'5' .or. callsign(3:3).eq.'6') .and. grid(1:4).eq.'FK87') .or. &
+ ((callsign(3:3).eq.'7' .or. callsign(3:3).eq.'8' .or. callsign(3:3).eq.'0') .and. grid(1:4).eq.'FK88')) then
+ lgvalid=.true.
+
+! Suriname PZ
+ else if(callsign(1:2).eq.'PZ') then
+ if(grid(1:2).eq.'GJ' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'6') &
+ lgvalid=.true.
+
+! Indonesia 7A..7I, 8A..8I, PK..PO, YB..YH
+ else if(callsign(2:2).gt.'J' .and. callsign(2:2).lt.'P') then
+ if((grid(1:2).eq.'NJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NI' .and. grid(3:3).gt.'8' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'OI' .and. .not.(grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4') &
+ .and. .not.(grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'PI' .and. .not.(grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'OJ' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'PJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'QI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'PH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4) .lt.'6') .or. &
+ (grid(3:3).eq.'7' .and. ((grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. grid(4:4).eq.'0' .or. grid(4:4).eq.'1' .or. &
+ grid(4:4).eq.'3')) .or. (grid(3:3).eq.'8' .and. grid(4:4).gt.'5'.and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ' .and. ((grid(3:3).gt.'4'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OI' .and. ((grid(4:4).eq.'1' .and. grid(3:3).gt.'1'.and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'2'.and. grid(3:3).lt.'6') .or. &
+ grid(3:4).eq.'44' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PI' .and. (grid(3:4).eq.'61' .or.grid(3:4).eq.'62'.or.grid(3:4).eq.'71'.or.grid(3:4).eq.'83'.or. &
+ grid(3:4).eq.'25' .or. grid(3:4).eq.'35' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'44' .or.grid(3:4).eq.'29')) then
+ lgvalid=.false.
+ endif
+endif
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'P1' .or. callsign(1:2).eq.'P0') then
+ lwrongcall=.true.; return
+
+ endif ! 'P'
+
+! Russia
+ else if(callsign(1:1).eq.'R') then
+ if((grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':').or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'6'))) .or. &
+ grid(1:2).eq.'LO' .or. grid(1:2).eq.'MO' .or. grid(1:2).eq.'NO' .or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'KP' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'30')) .or. grid(1:2).eq.'NP' &
+ .or. grid(1:2).eq.'OO' .or. grid(1:2).eq.'PO' .or. grid(1:2).eq.'LP' .or. grid(1:2).eq.'MP' .or. &
+ (grid(1:2).eq.'PN' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ grid(3:4).eq.'39' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'52' .or. grid(3:4).eq.'62')) .or.grid(1:4).eq.'MQ60'.or. &
+ (grid(1:2).eq.'QN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'QO' .and. (grid(3:3).eq.'0' .or. grid(3:3).eq.'1' .or. grid(3:3).eq.'8' .or. grid(3:3).eq.'9' .or. &
+ grid(3:4).eq.'49' .or. grid(3:4).eq.'59')) .or. grid(1:4).eq.'JO94' .or. &
+ grid(1:2).eq.'OP' .or. grid(1:2).eq.'PP' .or. grid(1:4).eq.'JB59' .or. grid(1:4).eq.'NQ03' .or. &
+ (grid(1:2).eq.'RP' .and. (grid(3:4).eq.'59' .or. grid(3:4).eq.'84'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'35' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'60' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'61')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'LO' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'60')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'LN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'1') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'48')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MO' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'9'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ (grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).eq.'3'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KN' .and. (grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. ((grid(4:4).gt.'6' .and. &
+ grid(4:4).lt.':') .or. grid(4:4).eq.'3'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. (grid(3:4).eq.'42' .or. grid(3:4).eq.'43' .or. grid(3:4).eq.'99')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OO' .and. grid(3:4).eq.'00') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'0') .or. &
+ grid(3:4).eq.'11' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'LP' .and. grid(4:4).eq.'9' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. &
+ grid(3:3).ne.'4' .and. grid(3:3).ne.'5') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PN' .and. (grid(3:4).eq.'56' .or. grid(3:4).eq.'83' .or. grid(3:4).eq.'93' .or. &
+ grid(3:4).eq.'94' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ endif
+endif
+
+ else if(callsign(1:1).eq.'S') then
+
+! Sweden 7S,8S,SA..SM
+ if(callsign(1:1).eq.'S' .and. callsign(2:2).gt.'@' .and. callsign(2:2).lt.'N') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JP' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'KP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'25'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JO' .and. (grid(3:4).eq.'85' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'JP' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. grid(3:4).eq.'89' .or. &
+ grid(3:4).eq.'99')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. (grid(3:4).eq.'13' .or. grid(3:4).eq.'14')) then; lgvalid=.false.
+ endif
+endif
+
+! Poland 3Z,HF,SN..SR
+ else if(callsign(1:1).eq.'S' .and. callsign(2:2).gt.'M' .and. callsign(2:2).lt.'S') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'20')) .or. &
+ grid(1:4).eq.'KN09' .or. grid(1:4).eq.'KN19' .or. grid(1:4).eq.'KO20' .or. grid(1:4).eq.'JN99' .or. &
+ grid(1:4).eq.'JN89') lgvalid=.true.
+
+! Greece J4,SV..SZ
+ else if(callsign(2:2).gt.'U' .and. callsign(2:2).lt.'[') then
+ if((grid(1:2).eq.'KM' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'46' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'14').and.grid(3:4).ne.'05').or. &
+ grid(1:4).eq.'JM99' .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. (grid(4:4).eq.'0' .or. grid(4:4).eq.'1'))) &
+ lgvalid=.true.
+
+! Slovenia S5
+ else if(callsign(1:2).eq.'S5') then
+ if(grid(1:2).eq.'JN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'7') &
+ lgvalid=.true.
+
+! Singapore 9V,S6
+ else if(callsign(1:2).eq.'9V') then
+ if(grid(1:2).eq.'OJ' .and. (grid(3:4).eq.'11' .or. grid(3:4).eq.'21')) lgvalid=.true.
+
+! Western Sahara S0
+ else if(callsign(1:2).eq.'S0') then
+ if(grid(1:2).eq.'IL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') &
+ lgvalid=.true.
+
+! Bangladesh S2,S3
+ else if(callsign(1:2).eq.'S2' .or. callsign(1:2).eq.'S3') then
+ if(grid(1:2).eq.'NL' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'7') &
+ lgvalid=.true.
+
+! South Africa H5,S4,S8,V9,ZR,ZS,ZT,ZU
+ else if(callsign(1:2).eq.'S4' .or. callsign(1:2).eq.'S8') then
+ if((grid(1:2).eq.'KG' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4'))) .or. &
+ (grid(1:2).eq.'KF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'JF' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'85') .or. &
+ (grid(1:2).eq.'JG' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KE83' .or. grid(1:4).eq.'KE93') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KF' .and. ((grid(4:4).eq.'5' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. grid(3:4).eq.'57')) lgvalid=.false.
+endif
+
+! Seychelles S7
+ else if(callsign(1:2).eq.'S7') then
+ if((grid(1:2).eq.'LI' .and. (grid(3:4).eq.'75' .or. grid(3:4).eq.'76' .or. grid(3:4).eq.'74' .or. grid(3:4).eq.'64' &
+ .or. grid(3:4).eq.'63' .or. grid(3:4).eq.'82' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'30'))&
+ .or. (grid(1:2).eq.'LH' .and. (grid(3:4).eq.'59' .or. grid(3:4).eq.'39'))) lgvalid=.true.
+
+! Sao Tome & Principe S9
+ else if(callsign(1:2).eq.'S9' .and. (grid(1:4).eq.'JJ30' .or. grid(1:4).eq.'JJ31')) then
+ lgvalid=.true.
+
+! Sudan 6T,6U,ST
+ else if(callsign(1:2).eq.'ST') then
+ if((grid(1:2).eq.'KK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ grid(1:4).eq.'KJ79') lgvalid=.true.
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'S1') then
+ lwrongcall=.true.; return
+
+ endif ! 'S'
+
+ else if(callsign(1:1).eq.'T') then
+
+! Turkey TA..TC,YM
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'D') then
+ if((grid(1:2).eq.'KM' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'KN' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'20' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'72')) .or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':'.and. &
+ grid(3:4).ne.'16')) lgvalid=.true.
+
+! Iceland TF
+ else if(callsign(1:2).eq.'TF') then
+ if((grid(1:2).eq.'HP' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'7').or. &
+ (grid(1:2).eq.'IP' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'7')) &
+ lgvalid=.true.
+
+! Corsica TK
+ else if(callsign(1:2).eq.'TK') then
+ if(grid(1:3).eq.'JN4' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') lgvalid=.true.
+
+! Gabon TR
+ else if(callsign(1:2).eq.'TR') then
+ if(callsign(1:5).eq.'TR8CA' .or. &
+ (grid(1:2).eq.'JJ' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52' .or. grid(3:4).eq.'62')) .or. &
+ (grid(1:2).eq.'JI' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'56'))) lgvalid=.true.
+
+! Tunisia 3V,TS
+ else if(callsign(1:2).eq.'TS') then
+ if(grid(1:2).eq.'JM' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') &
+ lgvalid=.true.
+
+! Guatemala TD,TG
+ else if(callsign(1:2).eq.'TG' .or. callsign(1:2).eq.'TD') then
+ if(grid(1:2).eq.'EK' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'8') &
+ lgvalid=.true.
+
+! Costa Rica, Cocos Island TE,TI
+ else if(callsign(1:2).eq.'TI' .or. callsign(1:2).eq.'TE') then
+ if((grid(1:2).eq.'EK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'EJ' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'EJ65') lgvalid=.true.
+
+! Afghanistan T6,YA
+ else if(callsign(1:2).eq.'T6') then
+ if((grid(1:2).eq.'MM' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(3:4).eq.'9')) lgvalid=.true.
+
+! San Marino T7
+ else if(callsign(1:2).eq.'T7' .and. grid(1:4).eq.'JN63') then
+ lgvalid=.true.
+
+! Palau T8
+ else if(callsign(1:2).eq.'T8') then
+ if(grid(1:2).eq.'PJ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'9') &
+ lgvalid=.true.
+
+! Cuba CL,CM,CO,T4
+ else if(callsign(1:2).eq.'T4') then
+ if((grid(1:2).eq.'EL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. grid(1:4).eq.'FK19') lgvalid=.true.
+
+! Martinique, Guadeloupe, St. Martin, St. Barthelemy, Reunion Island FM,FG,FS,FJ,FR TO
+ else if(callsign(1:2).eq.'TO') then
+ if((grid(1:3).eq.'FK9' .and. (grid(4:4).eq.'6' .or. grid(4:4).eq.'5' .or. grid(4:4).eq.'4')) .or. &
+ (grid(1:3).eq.'FK8' .and. (grid(4:4).eq.'8' .or. grid(4:4).eq.'7')) .or. &
+ (grid(1:2).eq.'LG' .and. (grid(3:4).eq.'79' .or. grid(3:4).eq.'78'))) lgvalid=.true.
+
+! Tuvalu
+ else if(callsign(1:2).eq.'T2') then
+ if((grid(1:2).eq.'RI' .and. (grid(3:4).eq.'91' .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'82' .or.grid(3:4).eq.'83'.or. &
+ grid(3:4).eq.'84')) .or. grid(1:4).eq.'RH99') lgvalid=.true.
+
+! Kiribati, Banana Island
+ else if(callsign(1:2).eq.'T3') then
+ if(grid(1:1).eq.'R') then
+ if((grid(1:3).eq.'RJ6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ (grid(1:3).eq.'RI7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(1:4).eq.'RI49' .or. grid(1:4).eq.'RI87' .or. grid(1:4).eq.'RI88') lgvalid=.true.
+ else if(grid(1:1).eq.'A') then
+ if((grid(1:2).eq.'AI' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'4' .and. &
+ grid(4:4).lt.'8') .or. grid(1:4).eq.'AJ94') lgvalid=.true.
+ else if(grid(1:1).eq.'B') then
+ if(grid(1:4).eq.'BJ03' .or. grid(1:4).eq.'BJ11' .or. grid(1:4).eq.'BJ12' .or. &
+ (grid(1:3).eq.'BI2' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ grid(1:4).eq.'BH48' .or. grid(1:4).eq.'BH49' .or. grid(1:4).eq.'BI40') lgvalid=.true.
+ endif
+
+! Cameroon
+ else if(callsign(1:2).eq.'TJ') then
+ if((grid(1:2).eq.'JJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4')) &
+ lgvalid=.true.
+
+! Central African Republic
+ else if(callsign(1:2).eq.'TL') then
+ if((grid(1:2).eq.'JJ' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).eq.'0')) lgvalid=.true.
+
+! Republic of the Congo
+ else if(callsign(1:2).eq.'TN') then
+ if((grid(1:2).eq.'JI' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4')) &
+ lgvalid=.true.
+
+! Chad
+ else if(callsign(1:2).eq.'TT') then
+ if((grid(1:2).eq.'JK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'JJ' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'KJ09' .or. &
+ (grid(1:2).eq.'KK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. &
+ (grid(1:2).eq.'JL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4').or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2')) &
+ lgvalid=.true.
+
+! Cote d'Ivoire:
+ else if(callsign(1:2).eq.'TU') then
+ if((grid(1:2).eq.'IJ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'IK' .and. (grid(3:4).eq.'60' .or. grid(3:4).eq.'70' .or. grid(3:4).eq.'50'))) lgvalid=.true.
+
+! Benin:
+ else if(callsign(1:2).eq.'TY') then
+ if((grid(1:2).eq.'JJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3')) &
+ lgvalid=.true.
+
+! Mali:
+ else if(callsign(1:2).eq.'TZ') then
+ if((grid(1:2).eq.'IK' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'IL' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'JL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2')) &
+ lgvalid=.true.
+
+! Chesterfield, French Polynesia, Austral, Marquesas, Clipperton Islands FK,TX
+ else if(callsign(1:2).eq.'TX') then
+ if((grid(1:2).eq.'QH' .and. (grid(3:4).eq.'90' .or. grid(3:4).eq.'91')) .or. grid(1:4).eq.'QG98' .or. &
+ (grid(1:2).eq.'BH' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'BG' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'BI9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'CI' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) .or. &
+ grid(1:4).eq.'CH09' .or. grid(1:4).eq.'DK50') lgvalid=.true.
+
+! Wallis & Futuna Islands FW,TW
+ else if(callsign(1:2).eq.'TW') then
+ if(grid(1:2).eq.'AH' .and. (grid(3:4).eq.'05' .or. grid(3:4).eq.'16')) lgvalid=.true.
+
+! France F,FA..FF,FI,FL,FN,FQ,FU,FV,FX,FZ,HW..HY,TH,TM,TP,TQ,TV
+ else if(callsign(2:2).eq.'H' .or. callsign(2:2).eq.'M' .or. callsign(2:2).eq.'P' .or. callsign(2:2).eq.'Q' .or. &
+ callsign(2:2).eq.'V') then
+ if((grid(1:2).eq.'IN' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'IN7' .and. (grid(4:4).eq.'7' .or. grid(4:4).eq.'8')) .or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'JN4' .and. (grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ grid(1:4).eq.'JN02' .or. grid(1:4).eq.'JN12' .or. grid(1:4).eq.'IN92' .or. &
+ (grid(1:2).eq.'JO' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'10' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'11'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'IN' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) lgvalid=.false.
+endif
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'T1' .or. callsign(1:2).eq.'T0') then
+ lwrongcall=.true.; return
+
+ endif ! 'T'
+
+ else if(callsign(1:1).eq.'U') then
+
+! Russia R, U0..U9, UA..UI
+ if((callsign(2:2).gt.'@' .and. callsign(2:2).lt.'J') .or. &
+ (callsign(2:2).gt.'/' .and. callsign(2:2).lt.':')) then
+ if((grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':').or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'6'))) .or. &
+ grid(1:2).eq.'LO' .or. grid(1:2).eq.'MO' .or. grid(1:2).eq.'NO' .or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'KP' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'30')) .or. grid(1:2).eq.'NP' &
+ .or. grid(1:2).eq.'OO' .or. grid(1:2).eq.'PO' .or. grid(1:2).eq.'LP' .or. grid(1:2).eq.'MP' .or. &
+ (grid(1:2).eq.'PN' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ grid(3:4).eq.'39' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'52' .or. grid(3:4).eq.'62')) .or.grid(1:4).eq.'MQ60'.or. &
+ (grid(1:2).eq.'QN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'QO' .and. (grid(3:3).eq.'0' .or. grid(3:3).eq.'1' .or. grid(3:3).eq.'8' .or. grid(3:3).eq.'9' .or. &
+ grid(3:4).eq.'49' .or. grid(3:4).eq.'59')) .or. grid(1:4).eq.'JO94' .or. &
+ grid(1:2).eq.'OP' .or. grid(1:2).eq.'PP' .or. grid(1:4).eq.'JB59' .or. grid(1:4).eq.'NQ03' .or. &
+ (grid(1:2).eq.'RP' .and. (grid(3:4).eq.'59' .or. grid(3:4).eq.'84'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'35' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'60' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'61')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'LO' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'60')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'LN' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'1') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'48')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MO' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'9'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ (grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).eq.'3'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KN' .and. (grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. ((grid(4:4).gt.'6' .and. &
+ grid(4:4).lt.':') .or. grid(4:4).eq.'3'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. (grid(3:4).eq.'42' .or. grid(3:4).eq.'43' .or. grid(3:4).eq.'99')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OO' .and. grid(3:4).eq.'00') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'0') .or. &
+ grid(3:4).eq.'11' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'LP' .and. grid(4:4).eq.'9' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. &
+ grid(3:3).ne.'4' .and. grid(3:3).ne.'5') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PN' .and. (grid(3:4).eq.'56' .or. grid(3:4).eq.'83' .or. grid(3:4).eq.'93' .or. &
+ grid(3:4).eq.'94' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ endif
+endif
+
+! Ukraine EM..EO,UR..UZ
+ else if(callsign(2:2).gt.'Q' .and. callsign(2:2).lt.'[') then
+ if((grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52' .or. grid(3:4).eq.'62')) .or. &
+ (grid(1:2).eq.'KN' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KO' .and. (grid(3:4).eq.'81' .or. grid(3:4).eq.'91')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KN' .and. ((grid(3:3).gt.'0'.and.grid(3:3).lt.'4'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'95' .or. grid(3:4).eq.'96')) then; lgvalid=.false.
+ endif
+endif
+
+! Kazakhstan UN..UQ
+ else if(callsign(2:2).gt.'M' .and. callsign(2:2).lt.'R') then
+ if((grid(1:2).eq.'MN' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'MO' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LO' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'NN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'NO' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or.grid(3:4).eq.'10'.or.grid(3:4).eq.'20')).or. &
+ (grid(1:2).eq.'MO' .and. (grid(3:4).eq.'45' .or. grid(3:4).eq.'55')) .or. &
+ (grid(1:2).eq.'MN' .and. ((grid(4:4).eq.'1' .and. (grid(3:3).eq.'3' .or.grid(3:3).eq.'4'.or.grid(3:3).eq.'5')).or. &
+ grid(3:4).eq.'40')) .or. &
+ (grid(1:3).eq.'NN0' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5')) lgvalid=.true.
+
+ endif ! 'U'
+
+ else if(callsign(1:1).eq.'V') then
+
+! Canada CF..CK,CY,CZ,VA..VG,VO,VX,VY,XJ..XO
+ if((callsign(2:2).gt.'@' .and. callsign(2:2).lt.'H') .or. callsign(1:2).eq.'VO' .or. callsign(1:2).eq.'VX' .or. &
+ callsign(1:2).eq.'VY') then
+ if((grid(1:2).eq.'CN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FN' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EN' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. grid(1:2).eq.'CO' .or. &
+ (grid(1:2).eq.'GN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ grid(1:2).eq.'FO' .or. grid(1:2).eq.'EO' .or. grid(1:2).eq.'DO' .or. &
+ (grid(1:2).eq.'GO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'DN'.and. grid(4:4).gt.'8' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'CP' .or. grid(1:2).eq.'DP' .or. grid(1:2).eq.'EP' .or. &
+ (grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'96')) .or. &
+ (grid(1:2).eq.'EQ' .and. (grid(3:4).eq.'15' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'24' .or.grid(3:4).eq.'71'.or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'79' .or. grid(3:4).eq.'84' .or. grid(3:4).eq.'86' .or.grid(3:4).eq.'96')).or. &
+ (grid(1:2).eq.'FR' .and. (grid(3:4).eq.'71' .or. grid(3:4).eq.'82')) .or. &
+ (grid(1:2).eq.'FQ' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'12')) .or. grid(1:4).eq.'GN03' .or. &
+ grid(1:4).eq.'FN93' .or. grid(1:4).eq.'ER60' .or. grid(1:4).eq.'DQ10' .or. grid(1:4).eq.'CQ71') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'EO' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'7' .and.grid(4:4).lt.':').or. &
+ (grid(4:4).eq.'7' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9') .or. grid(3:4).eq.'76' .or. grid(3:4).eq.'86')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'8').or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. grid(3:4).eq.'30'.or.grid(3:4).eq.'31'.or. &
+ grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EP' .and. ((grid(4:4).eq.'0' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(4:4).eq.'1' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9') .or. &
+ (grid(4:4).eq.'2' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CN' .and. (grid(3:4).eq.'68' .or. grid(3:4).eq.'98')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. &
+ grid(4:4).lt.'8') .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ endif
+endif
+
+! Australia AX,VH..VN,VZ
+ else if((callsign(2:2).gt.'G' .and. callsign(2:2).lt.'O') .or. callsign(1:2).eq.'VZ') then
+ if((grid(1:2).eq.'QG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7') .or. &
+ (grid(1:2).eq.'QF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7') .or. &
+ (grid(1:2).eq.'PF' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'OF' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'QE' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'19')) .or. &
+ (grid(1:2).eq.'QH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'OG' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ grid(1:2).eq.'PG' .or. grid(1:2).eq.'PH' .or. &
+! Heard Island, Macquarie Island
+ (callsign(1:3).eq.'VK0' .and. &
+ ((grid(1:2).eq.'MD' .and. (grid(3:4).eq.'66' .or. grid(3:4).eq.'67')) .or. &
+ (grid(1:2).eq.'QD' .and. (grid(3:4).eq.'95' .or. grid(3:4).eq.'94')))) .or. &
+! Cocos (Keeling) Islands, Lord Howe Island, Mellish Reef, Norfolk Island, Willis Island VK9
+ (callsign(1:3).eq.'VK9' .and. &
+ ((grid(1:2).eq.'NH' .and. (grid(3:4).eq.'87' .or. grid(3:4).eq.'88')) .or. &
+ grid(1:4).eq.'QF98' .or. grid(1:4).eq.'OH29' .or. &
+ (grid(1:2).eq.'RG' .and. (grid(3:4).eq.'30' .or. grid(3:4).eq.'31')) .or. &
+ (grid(1:2).eq.'QH' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'1' .and. &
+ grid(4:4).lt.'5')))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'QF' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') then; lgvalid=.false.
+ else if(grid(1:2).eq.'PF' .and. ((grid(3:3).gt.'/'.and.grid(3:3).lt.'8'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'7') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'7') .or. grid(3:4).eq.'57')) then; lgvalid=.false.
+ else if(grid(1:4).eq.'OF74') then; lgvalid=.false.
+ else if(grid(1:2).eq.'QH' .and. ((grid(3:3).eq.'3' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. grid(3:4).eq.'09')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OG' .and. (grid(3:4).eq.'60' .or. grid(3:4).eq.'69')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PH' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':' .and. &
+ grid(4:4).ne.'5' .and. grid(4:4).ne.'6') .or. &
+ (grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'9' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'59' .or. grid(3:4).eq.'79' .or. grid(3:4).eq.'89')) then; lgvalid=.false.
+ endif
+endif
+
+! India 8T..8Y,AT..AW,VT..VW
+ else if(callsign(2:2).gt.'S' .and. callsign(2:2).lt.'X') then
+ if((grid(1:2).eq.'MJ' .and. (grid(3:4).eq.'99' .or. grid(3:4).eq.'89' .or. grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'68')).or. &
+ (grid(1:2).eq.'MK' .and. ((grid(3:3).gt.'5'.and.grid(3:3).lt.':').or.grid(3:4).eq.'51'.or.grid(3:4).eq.'52')).or. &
+ (grid(1:2).eq.'NK' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or.grid(3:4).eq.'39')).or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(1:4).eq.'NM00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'MK' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'5') then; lgvalid=.false.
+ else if(grid(1:2).eq.'NK' .and. (grid(3:4).eq.'26' .or. grid(3:4).eq.'27')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'ML' .and. ((grid(3:3).gt.'4'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'5'.or.grid(4:4).eq.'8'.or. &
+ grid(4:4).eq.'9')) .or. grid(3:4).eq.'58' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NL' .and. ((grid(4:4).eq.'9' .and. grid(3:3).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(4:4).eq.'8' .and. grid(3:3).gt.'0' .and. grid(4:4).lt.'5') .or.grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'62')) then; lgvalid=.false.
+ endif
+endif
+
+! Hong Kong VR
+ else if(callsign(1:2).eq.'VR'.and. (grid(1:2).eq.'OL' .and. (grid(3:4).eq.'72' .or. grid(3:4).eq.'62'))) then
+ lgvalid=.true.
+
+! Antigua & Barbuda V2
+ else if(callsign(1:2).eq.'V2') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'86' .or. grid(3:4).eq.'97')) lgvalid=.true.
+
+! Belize V3
+ else if(callsign(1:2).eq.'V3') then
+ if((grid(1:2).eq.'EK' .and. grid(3:3).eq.'5' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'EK' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.'9')) lgvalid=.true.
+
+! St. Kitts & Nevis V4
+ else if(callsign(1:2).eq.'V4' .and. grid(1:4).eq.'FK87') then
+ lgvalid=.true.
+
+! Namibia V5
+ else if(callsign(1:2).eq.'V5') then
+ if((grid(1:2).eq.'JG' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JH' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'KG' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09')).or. &
+ (grid(1:2).eq.'KH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3')) &
+ lgvalid=.true.
+
+! Micronesia V6
+ else if(callsign(1:2).eq.'V6') then
+ if((grid(1:2).eq.'PJ' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'QJ' .and. ((grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. grid(3:4).eq.'71' .or. &
+ grid(3:4).eq.'73')) .or. &
+ (grid(1:2).eq.'RJ' .and. (grid(3:4).eq.'06' .or. grid(3:4).eq.'15')) .or. grid(1:4).eq.'PK90') lgvalid=.true.
+
+! Marshall Islands V7
+ else if(callsign(1:2).eq.'V7') then
+ if((grid(1:2).eq.'RJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'RK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'3') .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'39'))) lgvalid=.true.
+
+! Brunei Darussalam V8
+ else if(callsign(1:2).eq.'V8') then
+ if(grid(1:2).eq.'OJ' .and. (grid(3:4).eq.'74' .or. grid(3:4).eq.'75')) lgvalid=.true.
+
+! Bermuda VP9
+ else if(callsign(1:3).eq.'VP9' .and. grid(1:4).eq.'FM72') then
+ lgvalid=.true.
+
+! Chagos Islands VQ9
+ else if(callsign(1:3).eq.'VQ9') then
+ if(grid(1:2).eq.'MI' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') &
+ lgvalid=.true.
+
+! South Africa H5,S4,S8,V9,ZR,ZS,ZT,ZU
+ else if(callsign(1:2).eq.'V9') then
+ if((grid(1:2).eq.'KG' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4'))) .or. &
+ (grid(1:2).eq.'KF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'JF' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'85') .or. &
+ (grid(1:2).eq.'JG' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KE83' .or. grid(1:4).eq.'KE93') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KF' .and. ((grid(4:4).eq.'5' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. grid(3:4).eq.'57')) lgvalid=.false.
+endif
+
+! Anguilla, Montserrat, British Virgin Islands VP2
+ else if(callsign(1:3).eq.'VP2' .and. &
+ (grid(1:2).eq.'FK' .and. (grid(3:4).eq.'88' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'78'))) then
+ lgvalid=.true.
+
+! Turks & Caicos Islands VP5
+ else if((callsign(1:3).eq.'VP5' .or. callsign(1:3).eq.'VQ5') .and. &
+ (grid(1:2).eq.'FL' .and. (grid(3:4).eq.'31' .or. grid(3:4).eq.'41'))) then
+ lgvalid=.true.
+
+! Pitcairn Island, Ducie Island VP6
+ else if(callsign(1:3).eq.'VP6' .and. (grid(1:2).eq.'CG' .and. (grid(3:4).eq.'55' .or. grid(3:4).eq.'44' .or. &
+ grid(3:4).eq.'46' .or. grid(3:4).eq.'75'))) then
+ lgvalid=.true.
+
+! Falkland Islands, South Georgia Island, South Shetland Islands, South Orkney Islands, South Sandwich Islands VP8
+ else if(callsign(1:3).eq.'VP8') then
+ if((grid(1:2).eq.'FD' .and. grid(3:3).gt.'8' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9').or. &
+ grid(1:4).eq.'GD86' .or. &
+ (grid(1:2).eq.'HD' .and. ((grid(3:4).eq.'15' .or. grid(3:4).eq.'25' .or.grid(3:4).eq.'05' .or.grid(3:4).eq.'16'.or. &
+ grid(3:4).eq.'06') .or. (grid(1:3).eq.'HD6' .and.(grid(4:4).gt.'/' .and. grid(4:4).lt.'4')) .or. &
+ grid(1:4).eq.'HD53')) .or. &
+ grid(1:4).eq.'GC69' .or. grid(1:4).eq.'GC79') lgvalid=.true.
+
+! not valid callsigns
+ else if(callsign(1:2).eq.'V1' .or. callsign(1:2).eq.'V0') then
+ lwrongcall=.true.; return
+
+ endif ! 'V'
+
+! USA AA..AL,K,N,W
+ else if(callsign(1:1).eq.'W') then
+ if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':' .and. callsign(3:3).gt.'/' .and. callsign(3:3).lt.':') return ! checkcall
+ if((grid(1:2).eq.'FM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EL' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'DL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'EM' .or. grid(1:2).eq.'DM' .or. grid(1:2).eq.'EN' .or. &
+ (grid(1:2).eq.'CM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'DN' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:2).eq.'CO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. &
+ grid(1:2).eq.'BP' .or. &
+ (grid(1:2).eq.'BO' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AP' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ grid(1:4).eq.'FK28' .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'BL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'BK' .and. (grid(3:4).eq.'19' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'29')) .or. &
+ (grid(1:2).eq.'AL' .and. (grid(3:4).eq.'91' .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. &
+ grid(3:4).eq.'27' .or. grid(3:4).eq.'36' .or. grid(3:4).eq.'45' .or. grid(3:4).eq.'64' .or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:3).eq.'QK2' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'AO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'RO' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'3').or. &
+ grid(3:4).eq.'63')) .or. &
+ grid(1:4).eq.'AP30' .or. grid(1:4).eq.'QK36' .or. grid(1:4).eq.'QL20' .or. grid(1:4).eq.'RK39' .or. &
+ grid(1:4).eq.'AK56' .or. grid(1:4).eq.'AH48' .or. grid(1:4).eq.'JA00' .or. grid(1:4).eq.'RB32' .or. &
+ grid(1:4).eq.'CP00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FM' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'24')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9' &
+ .and. grid(3:4).ne.'28'.and. grid(3:4).ne.'58') .or. grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. &
+ grid(3:4).eq.'14')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DL' .and. (grid(3:4).eq.'78' .or. grid(3:4).eq.'88')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EN' .and. ((grid(3:3).eq.'9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':') .or. &
+ ((grid(3:3).eq.'8' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9' .and. grid(3:3).ne.'2'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CM' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FN' .and. ((grid(4:4).eq.'7' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'05' .or. grid(3:4).eq.'15' .or. grid(3:4).eq.'52')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') .or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'BO' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'3'.and.grid(4:4).lt.'9').or. &
+ (grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'24' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'35')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AP' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(4:4).gt.'3' .and. grid(4:4).lt.':'))) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'63' .or. &
+ grid(3:4).eq.'67' .or. grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'AO' .and. ((grid(3:3).eq.'4' .and. ((grid(4:4).gt.'2' .and. grid(4:4).lt.'7') .or. &
+ grid(4:4).eq.'8' .or. grid(4:4).eq.'9')) .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':' .and. grid(4:4).ne.'6') .or. &
+ ((grid(3:3).eq.'6' .or. grid(3:3).eq.'7') .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'62' .or. grid(3:4).eq.'97' .or. grid(3:4).eq.'86' .or. grid(3:4).eq.'87' .or.grid(3:4).eq.'31')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'BL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'21' .or. &
+ grid(3:4).eq.'22')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'RO' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'71')) then; lgvalid=.false.
+ endif
+endif
+
+ else if(callsign(1:1).eq.'X') then
+
+! Mexico, Revillagigedo 4A..4C, 6D..6J, XA..XI
+ if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'J') then
+ if((grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.':').or.grid(3:4).eq.'08'.or.grid(3:4).eq.'09')).or. &
+ (grid(1:2).eq.'EL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'EK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'34')) .or. &
+ (grid(1:2).eq.'DM' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'DK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'DK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'38'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2') .or. &
+ grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'33' .or. grid(3:4).eq.'60')) then
+ lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'17' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'21' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'32' .or. &
+ grid(3:4).eq.'62')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EK' .and. (grid(3:4).eq.'05' .or.grid(3:4).eq.'65'.or.grid(3:4).eq.'66'.or.grid(3:4).eq.'67'.or. &
+ grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'2') then; lgvalid=.false.
+ else if(grid(1:2).eq.'DK' .and. (grid(3:4).eq.'76' .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'86')) then; lgvalid=.false.
+ endif
+endif
+
+! Canada CF..CK,CY,CZ,VA..VG,VO,VX,VY,XJ..XO
+ else if(callsign(1:1).eq.'X' .and. callsign(2:2).gt.'I' .and. callsign(2:2).lt.'P') then
+ if((grid(1:2).eq.'CN' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FN' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'EN' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. grid(1:2).eq.'CO' .or. &
+ (grid(1:2).eq.'GN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ grid(1:2).eq.'FO' .or. grid(1:2).eq.'EO' .or. grid(1:2).eq.'DO' .or. &
+ (grid(1:2).eq.'GO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'DN'.and. grid(4:4).gt.'8' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'CP' .or. grid(1:2).eq.'DP' .or. grid(1:2).eq.'EP' .or. &
+ (grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'96')) .or. &
+ (grid(1:2).eq.'EQ' .and. (grid(3:4).eq.'15' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'24' .or.grid(3:4).eq.'71'.or. &
+ grid(3:4).eq.'73' .or. grid(3:4).eq.'79' .or. grid(3:4).eq.'84' .or. grid(3:4).eq.'86' .or.grid(3:4).eq.'96')).or. &
+ (grid(1:2).eq.'FR' .and. (grid(3:4).eq.'71' .or. grid(3:4).eq.'82')) .or. &
+ (grid(1:2).eq.'FQ' .and. (grid(3:4).eq.'50' .or. grid(3:4).eq.'12')) .or. grid(1:4).eq.'GN03' .or. &
+ grid(1:4).eq.'FN93' .or. grid(1:4).eq.'ER60' .or. grid(1:4).eq.'DQ10' .or. grid(1:4).eq.'CQ71') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'EO' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'7' .and.grid(4:4).lt.':').or. &
+ (grid(4:4).eq.'7' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'9') .or. grid(3:4).eq.'76' .or. grid(3:4).eq.'86')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'CO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'8').or. grid(3:4).eq.'08' .or. grid(3:4).eq.'18' .or. grid(3:4).eq.'30'.or.grid(3:4).eq.'31'.or. &
+ grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EP' .and. ((grid(4:4).eq.'0' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(4:4).eq.'1' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9') .or. &
+ (grid(4:4).eq.'2' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'CN' .and. (grid(3:4).eq.'68' .or. grid(3:4).eq.'98')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. &
+ grid(4:4).lt.'8') .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ endif
+endif
+
+! Burkina Faso XT
+ else if(callsign(1:2).eq.'XT') then
+ if((grid(1:2).eq.'IK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'IJ' .and. (grid(3:4).eq.'79' .or. grid(3:4).eq.'89'))) &
+ lgvalid=.true.
+
+! Cambodia XU
+ else if(callsign(1:2).eq.'XU') then
+ if(grid(1:2).eq.'OK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') &
+ lgvalid=.true.
+
+! Vietnam 3W,XV
+ else if(callsign(1:2).eq.'XV') then
+ if((grid(1:2).eq.'OL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'OK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'OJ19' .or. grid(1:4).eq.'OL41' .or. grid(1:4).eq.'OL23') lgvalid=.true.
+
+! Laos XW
+ else if(callsign(1:2).eq.'XW') then
+ if((grid(1:2).eq.'OK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'OL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3')) &
+ lgvalid=.true.
+
+! Macao XX9
+ else if(callsign(1:3).eq.'XX9' .and. grid(1:4).eq.'OL62') then
+ lgvalid=.true.
+
+ ! Chile 3G,CA..CE,XQ,XR
+ else if(callsign(1:2).eq.'XQ' .or. callsign(1:2).eq.'XR') then
+ if((grid(1:2).eq.'FF' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FG' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'8'))) .or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52')) .or. &
+ (grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'53' .or. grid(3:4).eq.'85')) .or. &
+ grid(1:4).eq.'EF96' .or. grid(1:4).eq.'FF06' .or. grid(1:4).eq.'EG93' .or. grid(1:4).eq.'FG03' .or. &
+ grid(1:4).eq.'DG52' .or. grid(1:4).eq.'DG73') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FF' .and. grid(3:3).eq.'3' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'41' .or. grid(3:4).eq.'29')) then; lgvalid=.false.
+ endif
+endif
+
+! Myanmar XY,XZ
+ else if(callsign(1:2).eq.'XY' .or. callsign(1:2).eq.'XZ') then
+ if((grid(1:2).eq.'NK' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'NL' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'OL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01'))) &
+ lgvalid=.true.
+
+! Greenland OX,XP
+ else if(callsign(1:2).eq.'XP') then
+ if((grid(1:2).eq.'GP' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'HP' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'HQ90' .or. &
+ (grid(1:2).eq.'GQ' .and. (grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'41' .or.grid(3:4).eq.'22'.or. &
+ grid(3:4).eq.'14' .or. grid(3:4).eq.'12')) .or. &
+ (grid(1:2).eq.'FQ' .and. (grid(3:4).eq.'76' .or. grid(3:4).eq.'67' .or. grid(3:4).eq.'57' .or.grid(3:4).eq.'56'.or. &
+ grid(3:4).eq.'38'))) lgvalid=.true.
+
+! China, Taiwan B, 3H..3U, XS
+ else if(callsign(1:2).eq.'XS') then
+ if(grid(1:2).eq.'OL' .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. grid(1:2).eq.'OM' .or. &
+ (grid(1:2).eq.'PM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(1:2).eq.'PN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8') .or. &
+ (grid(1:2).eq.'PO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ (grid(1:2).eq.'OK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'58' .or.grid(3:4).eq.'59')).or. &
+ grid(1:2).eq.'ON' .or. grid(1:4).eq.'OO90' .or. grid(1:4).eq.'OO91' .or. grid(1:2).eq.'NN' .or. grid(1:2).eq.'NM'.or. &
+ (grid(1:2).eq.'NL' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'MN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'NL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'7'.and. &
+ grid(3:4).ne.'83' .and. grid(3:4).ne.'84' .and. grid(3:4).ne.'85') .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'87')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'ON' .and.((grid(3:3).gt.'/'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'76' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PN' .and. ((grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'40' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'59' .or. &
+ grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).eq.'0') .or. &
+ grid(3:4).eq.'11' .or. grid(3:4).eq.'21')) then; lgvalid=.false.
+ endif
+endif
+
+! not valid callsigns X0...X9
+ else if(callsign(2:2).gt.'/' .and. callsign(2:2).lt.':') then
+ lwrongcall=.true.; return
+
+ endif ! 'X'
+
+ else if(callsign(1:1).eq.'Y') then
+
+! Romania YO..YR
+ if(callsign(2:2).gt.'N' .and. callsign(2:2).lt.'S') then
+ if(grid(1:2).eq.'KN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'9') &
+ lgvalid=.true.
+
+! Serbia YU,YT
+ else if(callsign(2:2).eq.'U' .or. callsign(2:2).eq.'T') then
+ if((grid(1:3).eq.'JN9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'7') .or. &
+ (grid(1:3).eq.'KN0' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7') .or. &
+ (grid(1:3).eq.'KN1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5')) lgvalid=.true.
+
+! Indonesia 7A..7I, 8A..8I, PK..PO, YB..YH
+ else if(callsign(2:2).gt.'A' .and. callsign(2:2).lt.'I') then
+ if((grid(1:2).eq.'NJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NI' .and. grid(3:3).gt.'8' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ grid(1:2).eq.'OI' .or. grid(1:2).eq.'PI' .or. &
+ (grid(1:2).eq.'OJ' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'PJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'QI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'PH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4) .lt.'6').or. &
+ (grid(3:3).eq.'7' .and. ((grid(4:4).gt.'5'.and. grid(4:4).lt.':') .or. grid(4:4).eq.'0' .or. grid(4:4).eq.'1'.or. &
+ grid(4:4).eq.'3')) .or. (grid(3:3).eq.'8' .and. grid(4:4).gt.'5'.and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ'.and.((grid(3:3).gt.'4'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OI' .and. ((grid(4:4).eq.'1' .and. grid(3:3).gt.'1'.and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'2'.and. grid(3:3).lt.'6') .or. &
+ grid(3:4).eq.'44' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PI' .and.(grid(3:4).eq.'61'.or.grid(3:4).eq.'62'.or.grid(3:4).eq.'71'.or.grid(3:4).eq.'83'.or. &
+ grid(3:4).eq.'25' .or. grid(3:4).eq.'35' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'29')) &
+ then; lgvalid=.false.
+ endif
+endif
+
+! Venezuela, Aves Island YV..YY 4M
+ else if(callsign(2:2).gt.'U' .and. callsign(2:2).lt.'Z') then
+ if((grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'60' .or. grid(3:4).eq.'70')) .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ grid(1:4).eq.'FK85') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'7' .and. &
+ grid(3:4).ne.'57') .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'93')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FJ' .and. (grid(3:4).eq.'32' .or.grid(3:4).eq.'72'.or.grid(3:4).eq.'82'.or.grid(3:4).eq.'92'.or. &
+ grid(3:4).eq.'91')) then; lgvalid=.false.
+ endif
+endif
+
+! Latvia YL
+ else if(callsign(1:2).eq.'YL') then
+ if((grid(1:2).eq.'KO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'KO' .and. (grid(3:4).eq.'25' .or. grid(3:4).eq.'35' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'28'))) &
+ lgvalid=.true.
+
+! Afghanistan T6,YA
+ else if(callsign(1:2).eq.'YA') then
+ if((grid(1:2).eq.'MM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(3:4).eq.'9')) lgvalid=.true.
+
+! Iraq HN,YI
+ else if(callsign(1:2).eq.'YI') then
+ if((grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'KM' .and.(grid(3:4).eq.'92' .or. grid(3:4).eq.'93')) .or. &
+ (grid(1:2).eq.'LL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+! Vanuatu YJ
+ else if(callsign(1:2).eq.'YJ') then
+ if((grid(1:2).eq.'RH' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ grid(1:4).eq.'RG49' .or. grid(1:4).eq.'RH50' .or. grid(1:4).eq.'RH36') lgvalid=.true.
+
+! Syria 6C,YK
+ else if(callsign(1:2).eq.'YK') then
+ if((grid(1:2).eq.'KM' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7').or. &
+ (grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8')) &
+ lgvalid=.true.
+
+! Turkey TA..TC,YM
+ else if(callsign(1:2).eq.'YM') then
+ if((grid(1:2).eq.'KM' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'KN' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'20' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'62' .or. grid(3:4).eq.'72')) .or. &
+ (grid(1:2).eq.'LN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':'.and. &
+ grid(3:4).ne.'16')) lgvalid=.true.
+
+! Nicaragua H6,H7,HT,YN
+ else if(callsign(1:2).eq.'YN') then
+ if(grid(1:2).eq.'EK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') &
+ lgvalid=.true.
+
+! El Salvador YS,HU
+ else if(callsign(1:2).eq.'YS') then
+ if(grid(1:2).eq.'EK' .and. (grid(3:4).eq.'53' .or. grid(3:4).eq.'54' .or. grid(3:4).eq.'63' .or. grid(3:4).eq.'43')) &
+ lgvalid=.true.
+
+! Fed. Rep. of Germany DA..DR, Y2..Y9
+ else if(callsign(1:1).eq.'Y' .and. callsign(2:2).gt.'1' .and. callsign(2:2).lt.':') then
+ if((grid(1:2).eq.'JO' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'45')) .or. &
+ (grid(1:2).eq.'JN' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':').or. &
+ grid(1:4).eq.'IB59') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JO' .and. ((grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'35')) lgvalid=.false.
+endif
+
+! not valid callsigns Y1,Y0
+ else if(callsign(1:2).eq.'Y1' .or. callsign(1:2).eq.'Y0') then
+ lwrongcall=.true.; return
+
+ endif ! 'Y'
+
+ else if(callsign(1:1).eq.'Z') then
+
+! North Macedonia Z3
+ if(callsign(1:2).eq.'Z3') then
+ if((grid(1:3).eq.'KN0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ grid(1:4).eq.'KN11' .or. grid(1:4).eq.'KN11') lgvalid=.true.
+
+! Republic of Kosovo Z6
+ else if(callsign(1:2).eq.'Z6' .and. (grid(1:4).eq.'KN02' .or. grid(1:4).eq.'KN03')) then
+ lgvalid=.true.
+
+! New Zealand, Chatham Islands, Kermadec Islands, N.Z. Subantarctic Is. ZK ZL ZM
+ else if(callsign(2:2).gt.'J' .and. callsign(2:2).lt.'N') then
+ if((grid(1:2).eq.'RF' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'RE' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':') .or. &
+ grid(1:4).eq.'AE16' .or. grid(1:4).eq.'AE15' .or. grid(1:4).eq.'RE31' .or. grid(1:4).eq.'RE90' .or. &
+ grid(1:4).eq.'RE92' .or. grid(1:4).eq.'AF10' .or. grid(1:4).eq.'AG09' .or. grid(1:4).eq.'AG08' .or. &
+ grid(1:4).eq.'RD29' .or. grid(1:4).eq.'RD39' .or. grid(1:4).eq.'RD47') lgvalid=.true.
+
+! South Africa H5,S4,S8,V9,ZR,ZS,ZT,ZU
+ else if(callsign(2:2).gt.'Q' .and. callsign(2:2).lt.'V') then
+ if((grid(1:2).eq.'KG' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8').or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4'))) .or. &
+ (grid(1:2).eq.'KF' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'JF' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'85') .or. &
+ (grid(1:2).eq.'JG' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KE83' .or. grid(1:4).eq.'KE93') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'KF' .and. ((grid(4:4).eq.'5' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6') .or. &
+ (grid(4:4).eq.'6' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. grid(3:4).eq.'57')) lgvalid=.false.
+endif
+
+! Paraguay ZP
+ else if(callsign(1:2).eq.'ZP') then
+ if((grid(1:2).eq.'GG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FG' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ grid(1:4).eq.'FH90' .or. grid(1:4).eq.'GH00' .or. grid(1:4).eq.'FG95') lgvalid=.true.
+
+! Albania ZA
+ else if(callsign(1:2).eq.'ZA') then
+ if((grid(1:3).eq.'JN9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:3).eq.'KN0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ grid(1:4).eq.'JM99' .or. grid(1:4).eq.'KM09') lgvalid=.true.
+
+! Gibraltar ZB,ZG
+ else if((callsign(1:2).eq.'ZB' .or. callsign(1:2).eq.'ZG') .and. grid(1:4).eq.'IM76') then
+ lgvalid=.true.
+
+! UK Base Areas in Cyprus
+ else if(callsign(1:3).eq.'ZC4' .and. grid(1:4).eq.'KM64') then
+ lgvalid=.true.
+
+! Zimbabwe Z2
+ else if(callsign(1:2).eq.'Z2') then
+ if((grid(1:2).eq.'KH' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'KG' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Republic of South Sudan Z8
+ else if(callsign(1:2).eq.'Z8') then
+ if((grid(1:2).eq.'KJ' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KK' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3')) &
+ lgvalid=.true.
+
+! St. Helena ZD7
+ else if(callsign(1:3).eq.'ZD7' .and. (grid(1:4).eq.'IH74' .or. grid(1:4).eq.'IH73')) then
+ lgvalid=.true.
+
+! Ascension Island ZD8
+ else if(callsign(1:3).eq.'ZD8' .and. grid(1:4).eq.'II22') then
+ lgvalid=.true.
+
+! Tristan da Cunha & Gough ZD9
+ else if(callsign(1:3).eq.'ZD9' .and. (grid(1:4).eq.'IF32' .or. grid(1:4).eq.'IE49' .or. grid(1:4).eq.'IE59')) then
+ lgvalid=.true.
+
+! Cayman Islands ZF
+ else if(callsign(1:2).eq.'ZF' .and. (grid(1:4).eq.'EK99' .or. grid(1:4).eq.'FK09')) then
+ lgvalid=.true.
+
+! Tokelau Islands ZK3
+ else if(callsign(1:3).eq.'ZK3' .and. (grid(1:4).eq.'AI31' .or. grid(1:4).eq.'AI40')) then
+ lgvalid=.true.
+
+! Brazil PP..PY, ZV..ZZ
+ else if(callsign(2:2).gt.'U' .and. callsign(2:2).lt.'[') then
+ if((grid(1:2).eq.'GG' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.':') .or. grid(3:4).eq.'09')) .or. &
+ (grid(1:2).eq.'HI' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6'.and. &
+ grid(3:4).ne.'25') .or. grid(3:4).eq.'06' .or. grid(3:4).eq.'07' .or. grid(3:4).eq.'36')) .or. &
+ (grid(1:2).eq.'HH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. &
+ (grid(1:2).eq.'GH' .and. grid(3:4).ne.'01') .or. grid(1:2).eq.'GI' .or. &
+ (grid(1:2).eq.'GF' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'36')) .or. &
+ (grid(1:2).eq.'GJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4').or. &
+ grid(3:4).eq.'04' .or. grid(3:4).eq.'44')) .or. &
+ (grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'95')) .or. &
+ (grid(1:2).eq.'FI' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'93' .or. grid(3:4).eq.'94' .or. grid(3:4).eq.'95')) .or. &
+ grid(1:4).eq.'HG59' .or. grid(1:4).eq.'HJ50') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'GG' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. &
+ grid(4:4).lt.'6' .and. grid(3:4).ne.'64' .and. grid(3:4).ne.'65') .or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'7'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'HH' .and. (grid(3:3).eq.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GI' .and. ((grid(3:3).gt.'7'.and.grid(3:3).lt.':'.and.grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GF' .and. (grid(3:4).eq.'17' .or. grid(3:4).eq.'27')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'GJ' .and. (grid(3:4).eq.'13' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'52' .or. &
+ grid(3:4).eq.'53')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FJ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'FI' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'5'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'76' .or. grid(3:4).eq.'68')) then; lgvalid=.false.
+ endif
+endif
+
+! not valid callsigns Z1 Z7 Z9
+ else if(callsign(2:2).eq.'1' .or. callsign(2:2).eq.'7' .or. callsign(2:2).eq.'9') then
+ lwrongcall=.true.; return
+
+ endif ! 'Z'
+
+ endif ! end of block L..Z
+
+4 if(callsign(1:1).eq.'1') then
+
+! Sov Mil Order of Malta 1A
+ if(callsign(1:2).eq.'1A' .and. grid(1:4).eq.'JN61') then
+ lgvalid=.true.
+
+! 1B
+ else if(callsign(1:2).eq.'1B') then
+ if((grid(1:3).eq.'KM6' .or. grid(1:3).eq.'KM7') .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'6') lgvalid=.true.
+
+! Spratly Islands 1S,9M0,BM9S,BN9S,BO9S,BP9S,BQ9S,BU9S,BV9S,BW9S,BX9S
+ else if(callsign(1:2).eq.'1S') then
+ if((grid(1:2).eq.'OK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! not valid callsigns 1C..1R 1T..1Z
+ else if((callsign(2:2).gt.'B' .and. callsign(2:2).lt.'S') .or. (callsign(2:2).gt.'S' .and. callsign(2:2).lt.'[')) then
+ lwrongcall=.true.; return
+
+ endif ! '1'
+
+ else if(callsign(1:1).eq.'2') then
+
+! UK GB / 2E,G,M / 2D,GD,GT,MD,MT / 2I,GI,GN,MI,MN / 2J,GH,GJ,MH,MJ / 2A,2M,GM,GS,MA,MM,MS / 2U,GP,GU,MP,MU / 2W,GC,GW,MC,MW
+ if(callsign(2:2).eq.'E' .or. callsign(2:2).eq.'A' .or. callsign(2:2).eq.'M' .or. callsign(2:2).eq.'W' .or. &
+ callsign(2:2).eq.'I' .or. callsign(2:2).eq.'J' .or. callsign(2:2).eq.'U' .or. callsign(2:2).eq.'D') then
+ if((grid(1:2).eq.'IO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'JO0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(1:4).eq.'IP90' .or. grid(1:4).eq.'IN69' .or. grid(1:4).eq.'IN89' .or. grid(1:4).eq.'IO37') lgvalid=.true.
+
+if(lgvalid .and. grid(1:2).eq.'IO') then
+ if((grid(1:3).eq.'IO5' .and. grid(4:4).ne.'4' .and. grid(4:4).ne.'7') .or. &
+ (grid(1:3).eq.'IO6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ grid(3:4).eq.'96' .or. grid(3:4).eq.'98') lgvalid=.false.
+endif
+
+! not valid callsigns other 2x
+ else
+ lwrongcall=.true.; return
+
+ endif ! '2'
+
+ else if(callsign(1:1).eq.'3') then
+
+! Poland 3Z,HF,SN..SR
+ if(callsign(1:2).eq.'3Z') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'KO' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'20')) .or. &
+ grid(1:4).eq.'KN09' .or. grid(1:4).eq.'KN19' .or. grid(1:4).eq.'KO20' .or. grid(1:4).eq.'JN99' .or. &
+ grid(1:4).eq.'JN89') lgvalid=.true.
+
+! Monaco 3A
+ else if(callsign(1:2).eq.'3A' .and. grid(1:4).eq.'JN33') then
+ lgvalid=.true.
+
+ ! Chile 3G,CA..CE,XQ,XR
+ else if(callsign(1:2).eq.'3G') then
+ if((grid(1:2).eq.'FF' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FG' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'8'))) .or. &
+ (grid(1:2).eq.'FE' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'FH' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(3:4).eq.'52')) .or. &
+ (grid(1:2).eq.'FD' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'53' .or. grid(3:4).eq.'85')) .or. &
+ grid(1:4).eq.'EF96' .or. grid(1:4).eq.'FF06' .or. grid(1:4).eq.'EG93' .or. grid(1:4).eq.'FG03' .or. &
+ grid(1:4).eq.'DG52' .or. grid(1:4).eq.'DG73') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FF' .and. grid(3:3).eq.'3' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') then; lgvalid=.false.
+ else if(grid(1:2).eq.'FE' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'41' .or. grid(3:4).eq.'29')) then; lgvalid=.false.
+ endif
+endif
+
+! Agalega & St. Brandon 3B6,3B7
+ else if((callsign(1:3).eq.'3B6' .or. callsign(1:3).eq.'3B7') .and. (grid(1:4).eq.'LH89' .or. grid(1:4).eq.'LH93')) then
+ lgvalid=.true.
+
+! Mauritius 3B8
+ else if(callsign(1:3).eq.'3B8' .and. (grid(1:4).eq.'LG89' .or. grid(1:4).eq.'LH80')) then
+ lgvalid=.true.
+
+! Rodriguez Island 3B9
+ else if(callsign(1:3).eq.'3B9' .and. grid(1:4).eq.'MH10') then
+ lgvalid=.true.
+
+! Equatorial Guinea 3C, Annobon Island 3C0
+ else if(callsign(1:2).eq.'3C') then
+ if((grid(1:3).eq.'JJ4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. grid(1:4).eq.'JJ51' .or. &
+ grid(1:4).eq.'JJ52' .or. grid(1:4).eq.'JI28') lgvalid=.true.
+
+! Fiji, Conway Reef, Rotuma Island 3D2
+ else if(callsign(1:3).eq.'3D2') then
+ if((grid(1:2).eq.'RH' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4').or. &
+ (grid(1:3).eq.'AH0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ grid(1:4).eq.'RG78' .or. grid(1:4).eq.'AG08' .or. grid(1:4).eq.'AG09') lgvalid=.true.
+
+! Kingdom of eSwatini 3DA
+ else if(callsign(1:3).eq.'3DA') then
+ if((grid(1:3).eq.'KG5' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5') .or. grid(1:4).eq.'KG63' .or. &
+ grid(1:4).eq.'KG64') lgvalid=.true.
+
+! Tunisia 3V,TS
+ else if(callsign(1:2).eq.'3V') then
+ if(grid(1:2).eq.'JM' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') &
+ lgvalid=.true.
+
+! Vietnam 3W,XV
+ else if(callsign(1:2).eq.'3W') then
+ if((grid(1:2).eq.'OL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'OK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'OJ19' .or. grid(1:4).eq.'OL41' .or. grid(1:4).eq.'OL23') lgvalid=.true.
+
+! Guinea 3X
+ else if(callsign(1:2).eq.'3X') then
+ if((grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'IK' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ grid(1:4).eq.'IJ39') lgvalid=.true.
+
+! Bouvet, Peter 1st Island 3Y
+ else if(callsign(1:3).eq.'3Y' .and. (grid(1:4).eq.'JD15' .or. grid(1:4).eq.'EC41')) then
+ lgvalid=.true.
+
+! Panama 3E,3F,H3,H8,H9,HO,HP
+ else if(callsign(2:2).eq.'E' .or. callsign(2:2).eq.'F') then
+ if((grid(1:2).eq.'FJ' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'09' .or. grid(3:4).eq.'17' .or. &
+ grid(3:4).eq.'18')) .or. &
+ (grid(1:2).eq.'EJ' .and. (grid(3:4).eq.'88' .or. grid(3:4).eq.'89' .or. grid(3:4).eq.'97' .or. &
+ grid(3:4).eq.'98' .or. grid(3:4).eq.'99'))) lgvalid=.true.
+
+! China, Taiwan B, 3H..3U, XS
+ else if(callsign(2:2).gt.'G' .and. callsign(2:2).lt.'V') then
+ if(len_trim(callsign).gt.5) return ! checkcall
+ if(grid(1:2).eq.'OL' .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. grid(1:2).eq.'OM' .or. &
+ (grid(1:2).eq.'PM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(1:2).eq.'PN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8') .or. &
+ (grid(1:2).eq.'PO' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. &
+ (grid(1:2).eq.'OK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'58' .or.grid(3:4).eq.'59')).or. &
+ grid(1:2).eq.'ON' .or. grid(1:4).eq.'OO90' .or. grid(1:4).eq.'OO91' .or. grid(1:2).eq.'NN' .or. grid(1:2).eq.'NM'.or. &
+ (grid(1:2).eq.'NL' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'MN' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'NL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'7'.and. &
+ grid(3:4).ne.'83' .and. grid(3:4).ne.'84' .and. grid(3:4).ne.'85') .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'87')) &
+ then; lgvalid=.false.
+ else if(grid(1:2).eq.'ON' .and.((grid(3:3).gt.'/'.and.grid(3:3).lt.'5'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'4' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'76' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PN' .and. ((grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ (grid(3:3).eq.'5' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5') .or. &
+ grid(3:4).eq.'40' .or. grid(3:4).eq.'50' .or. grid(3:4).eq.'51' .or. grid(3:4).eq.'59' .or. &
+ grid(3:4).eq.'69' .or. grid(3:4).eq.'79')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'8') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).eq.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).eq.'0') .or. &
+ grid(3:4).eq.'11' .or. grid(3:4).eq.'21')) then; lgvalid=.false.
+ endif
+endif
+
+ endif ! '3'
+
+ else if(callsign(1:1).eq.'4') then
+
+! Venezuela, Aves Island YV..YY 4M
+ if(callsign(1:2).eq.'4M') then
+ if((grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'60' .or. grid(3:4).eq.'70')) .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ grid(1:4).eq.'FK85') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'2' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'7' .and. &
+ grid(3:4).ne.'57') .or. grid(3:4).eq.'92' .or. grid(3:4).eq.'93')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'FJ' .and. (grid(3:4).eq.'32' .or.grid(3:4).eq.'72'.or.grid(3:4).eq.'82'.or.grid(3:4).eq.'92'.or. &
+ grid(3:4).eq.'91')) then; lgvalid=.false.
+ endif
+endif
+
+! Israel 4X, 4Z
+ else if(callsign(1:2).eq.'4X' .or. callsign(1:2).eq.'4Z') then
+ if((grid(1:3).eq.'KM7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') .or. grid(1:4).eq.'KL79') lgvalid=.true.
+
+! Montenegro 4O
+ else if(callsign(1:2).eq.'4O') then
+ if((grid(1:3).eq.'JN9' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.'4') .or. grid(1:4).eq.'KN02' .or. &
+ grid(1:4).eq.'KN03') lgvalid=.true.
+
+! Sri Lanka 4P,4Q,4R,4S
+ else if(callsign(2:2).gt.'O' .and. callsign(2:2).lt.'T') then
+ if((grid(1:3).eq.'MJ9' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(1:3).eq.'NJ0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':')) lgvalid=.true.
+
+! Philippines 4D,4E,4F,4G,4H,4I,DU,DV,DW,DX,DY,DZ
+ else if(callsign(2:2).gt.'C' .and. callsign(2:2).lt.'J') then
+ if((grid(1:2).eq.'PK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4') .or. &
+ (grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'04')) .or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'OK' .and. grid(3:3).eq.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7') .or. &
+ (grid(1:2).eq.'PL' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ grid(1:4).eq.'OK70' .or. grid(1:4).eq.'OK71') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PK' .and. ((grid(3:3).eq.'3' .and. grid(4:4).gt.'0' .and. grid(4:4).lt.':') .or. &
+ (grid(3:3).eq.'2' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':'))) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PJ' .and. (grid(3:4).eq.'08' .or. grid(3:4).eq.'15')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ' .and. (grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) then; lgvalid=.false.
+ endif
+endif
+
+! Azerbaijan 4J, 4K
+ else if(callsign(1:2).eq.'4J' .or. callsign(1:2).eq.'4J') then
+ if((grid(1:2).eq.'LN' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'LM' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'LN50') lgvalid=.true.
+
+! Georgia 4L
+ else if(callsign(1:2).eq.'4J' .or. callsign(1:2).eq.'4J') then
+ if(grid(1:2).eq.'LN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4') &
+ lgvalid=.true.
+
+! ITU HQ, United Nations HQ, Vienna Intl Ctr
+ else if(callsign(2:2).eq.'U' .and. &
+ (callsign(1:6).eq.'4U1ITU' .or. callsign(1:5).eq.'4U1UN' .or. callsign(1:6).eq.'4U1VIC' .or. &
+ grid(1:4).eq.'JN88')) then
+ lgvalid=.true.
+
+! Mexico, Revillagigedo 4A..4C, 6D..6J, XA..XI
+ else if(callsign(2:2).gt.'@' .and. callsign(2:2).lt.'D') then
+ if((grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.':').or.grid(3:4).eq.'08'.or.grid(3:4).eq.'09')).or. &
+ (grid(1:2).eq.'EL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'EK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'34')) .or. &
+ (grid(1:2).eq.'DM' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'DK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'DK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'38'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2') .or. &
+ grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'33' .or. grid(3:4).eq.'60')) then
+ lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'17' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'21' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'32' .or. &
+ grid(3:4).eq.'62')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EK' .and. (grid(3:4).eq.'05' .or.grid(3:4).eq.'65'.or.grid(3:4).eq.'66'.or.grid(3:4).eq.'67'.or. &
+ grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'2') then; lgvalid=.false.
+ else if(grid(1:2).eq.'DK' .and. (grid(3:4).eq.'76' .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'86')) then; lgvalid=.false.
+ endif
+endif
+
+! Haiti 4V,HH
+ else if(callsign(1:2).eq.'4V') then
+ if((grid(1:2).eq.'FK' .and. (grid(3:4).eq.'38' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'48' .or. &
+ grid(3:4).eq.'49')) .or. grid(1:4).eq.'FL30') lgvalid=.true.
+
+! Timor - Leste 4W
+ else if(callsign(1:2).eq.'4W') then
+ if(grid(1:2).eq.'PI' .and. (grid(3:4).eq.'20' .or. grid(3:4).eq.'21' .or. grid(3:4).eq.'31')) lgvalid=.true.
+
+! Peru 4T,OA..OC
+ else if(callsign(1:2).eq.'4T') then
+ if((grid(1:2).eq.'FH' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'FI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:3).eq.'EI9' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'7')) lgvalid=.true.
+
+ endif ! '4'
+
+ else if(callsign(1:1).eq.'5') then
+
+! Denmark 5P,5Q,OU,OV,OZ
+ if(callsign(1:2).eq.'5P' .or. callsign(1:2).eq.'5Q') then
+ if(grid(1:2).eq.'JO' .and. &
+ ((grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'75' .or. grid(3:4).eq.'76')) lgvalid=.true.
+
+! Cyprus 5B,C4,H2,P3
+ else if(callsign(1:2).eq.'5B') then
+ if((grid(1:3).eq.'KM6' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5')) .or. &
+ (grid(1:3).eq.'KM7' .and. (grid(4:4).eq.'4' .or. grid(4:4).eq.'5'))) lgvalid=.true.
+
+! Morocco 5C..5G,CN
+ else if(callsign(2:2).gt.'B' .and. callsign(2:2).lt.'H') then
+ if((grid(1:2).eq.'IM' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6').or. &
+ (grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'6'.and.grid(4:4).gt.'0'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'69' .or. grid(3:4).eq.'79'))) lgvalid=.true.
+
+! Libya 5A
+ else if(callsign(1:2).eq.'5A') then
+ if((grid(1:2).eq.'JM' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'/' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'KM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'JL' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3') .or. &
+ (grid(1:2).eq.'JM' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'53')) .or. &
+ grid(1:4).eq.'JL91' .or. grid(1:4).eq.'KK19') lgvalid=.true.
+
+! Tanzania 5H, 5I
+ else if(callsign(1:2).eq.'5H' .or. callsign(1:2).eq.'5I') then
+ if((grid(1:2).eq.'KI' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'KH' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Colombia 5J,5K,HJ,HK
+ else if(callsign(1:2).eq.'5K' .or. callsign(1:2).eq.'5J') then
+ if((grid(1:2).eq.'FJ' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'7') .or. &
+ grid(3:4).eq.'01' .or. grid(3:4).eq.'02' .or. grid(3:4).eq.'03')) .or. &
+ (grid(1:2).eq.'FK' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3' .and. &
+ grid(3:4).ne.'22') .or. &
+ (grid(1:2).eq.'FI' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'6' .and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'45' .or. grid(3:4).eq.'55' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'56') .and.grid(3:4).ne.'27').or. &
+ (grid(1:2).eq.'EJ' .and. (grid(3:4).eq.'93' .or. grid(3:4).eq.'94')) .or. grid(1:4).eq.'EK92') lgvalid=.true.
+
+! Liberia 5L,5M,6Z,A8,D5,EL
+ else if(callsign(1:2).eq.'5L' .or. callsign(1:2).eq.'5M') then
+ if(grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and.grid(4:4).lt.'9'.and. &
+ grid(3:4).ne.'67' .and. grid(3:4).ne.'67') lgvalid=.true.
+
+! Nigeria 5N,5O
+ else if(callsign(1:2).eq.'5N' .or. callsign(1:2).eq.'5O') then
+ if((grid(1:2).eq.'JJ' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'4')) &
+ lgvalid=.true.
+
+! Madagascar 5R,5S,6X
+ else if(callsign(1:2).eq.'5R' .or. callsign(1:2).eq.'5S') then
+ if((grid(1:2).eq.'LH' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'7').or. &
+ (grid(1:2).eq.'LG' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(1:2).eq.'LH' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'47' .or. grid(3:4).eq.'48')) lgvalid=.true.
+
+! Mauritania 5T
+ else if(callsign(1:2).eq.'5T') then
+ if((grid(1:2).eq.'IK' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'8'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'34' .or. grid(3:4).eq.'44')) .or. &
+ (grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'7'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'6').or. &
+ grid(3:4).eq.'56' .or. grid(3:4).eq.'66' .or. grid(3:4).eq.'57' .or. grid(3:4).eq.'75'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'IK' .and. grid(3:4).eq.'15' .or. grid(3:4).eq.'25') then
+ lgvalid=.false.
+ else if(grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'0'.and.grid(3:3).lt.'3'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'6').or. &
+ grid(3:4).eq.'34' .or. grid(3:4).eq.'35')) then; lgvalid=.false.
+ endif
+endif
+
+! Niger 5U
+ else if(callsign(1:2).eq.'5U') then
+ if((grid(1:2).eq.'JK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JL' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'3').or. &
+ grid(1:4).eq.'JK11' .or. &
+ grid(1:2).eq.'JL' .and. (grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'53' .or. grid(3:4).eq.'63')) &
+ lgvalid=.true.
+
+! Togo 5V
+ else if(callsign(1:2).eq.'5V') then
+ if((grid(1:3).eq.'JJ0' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'JK' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01')) .or. &
+ (grid(1:2).eq.'IK' .and. (grid(3:4).eq.'90' .or. grid(3:4).eq.'91'))) lgvalid=.true.
+
+! Samoa 5W
+ else if(callsign(1:2).eq.'5W') then
+ if(grid(1:2).eq.'AH' .and. (grid(3:4).eq.'36' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'45')) lgvalid=.true.
+
+! Uganda 5X
+ else if(callsign(1:2).eq.'5X') then
+ if((grid(1:2).eq.'KJ' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4').or. &
+ (grid(1:2).eq.'KI' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).eq.'9') .or. &
+ (grid(1:2).eq.'KJ' .and. (grid(3:4).eq.'40' .or. grid(3:4).eq.'64' .or. grid(3:4).eq.'74')) .or. &
+ (grid(1:2).eq.'KI' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'58'))) &
+ lgvalid=.true.
+
+! Kenya 5Y,5Z
+ else if(callsign(1:2).eq.'5Z' .or. callsign(1:2).eq.'5Y') then
+ if((grid(1:2).eq.'KI' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KJ' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'LI' .and. grid(3:3).eq.'0' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'LJ' .and. grid(3:3).eq.'0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ grid(1:4).eq.'KJ60' .or. grid(1:4).eq.'KI69') lgvalid=.true.
+
+ endif ! '5'
+
+ else if(callsign(1:1).eq.'6') then
+
+! Syria 6C,YK
+ if(callsign(1:2).eq.'6C') then
+ if((grid(1:2).eq.'KM' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'7').or. &
+ (grid(1:2).eq.'LM' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8')) &
+ lgvalid=.true.
+
+! Mexico, Revillagigedo 4A..4C, 6D..6J, XA..XI
+ else if(callsign(2:2).gt.'C' .and. callsign(2:2).lt.'K') then
+ if((grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.':').or.grid(3:4).eq.'08'.or.grid(3:4).eq.'09')).or. &
+ (grid(1:2).eq.'EL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8').or. &
+ (grid(1:2).eq.'EK' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'34')) .or. &
+ (grid(1:2).eq.'DM' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3').or. &
+ (grid(1:2).eq.'DK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'5' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'DK' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'28' .or. grid(3:4).eq.'38'))) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'DL' .and. ((grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2') .or. &
+ grid(3:4).eq.'22' .or. grid(3:4).eq.'23' .or. grid(3:4).eq.'32' .or. grid(3:4).eq.'33' .or. grid(3:4).eq.'60')) then
+ lgvalid=.false.
+ else if(grid(1:2).eq.'EL' .and. ((grid(3:3).gt.'1'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'2'.and.grid(4:4).lt.'8').or. &
+ grid(3:4).eq.'17' .or. grid(3:4).eq.'20' .or. grid(3:4).eq.'21' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'32' .or. &
+ grid(3:4).eq.'62')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'EK' .and. (grid(3:4).eq.'05' .or.grid(3:4).eq.'65'.or.grid(3:4).eq.'66'.or.grid(3:4).eq.'67'.or. &
+ grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'DM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'2') then; lgvalid=.false.
+ else if(grid(1:2).eq.'DK' .and. (grid(3:4).eq.'76' .or. grid(3:4).eq.'77' .or. grid(3:4).eq.'86')) then; lgvalid=.false.
+ endif
+endif
+
+! Republic of Korea 6K,6L,6M,6N,D7,D8,D9,DS,DT,HL
+ else if(callsign(1:1).eq.'6' .and. callsign(2:2).gt.'J' .and. callsign(2:2).lt.'O') then
+ if((grid(1:3).eq.'PM3' .and. grid(4:4).gt.'2' .and. grid(4:4).lt.'9') .or. &
+ (grid(1:3).eq.'PM4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'9') .or. &
+ grid(1:4).eq.'PM24' .or. grid(1:4).eq.'PM57' .or. grid(1:4).eq.'GC07') lgvalid=.true. ! DT8A in GC07OS South Shetland Islands
+
+! Senegal 6V,6W
+ else if(callsign(1:2).eq.'6V' .or. callsign(1:2).eq.'6W') then
+ if(grid(1:2).eq.'IK' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'42' .or. grid(3:4).eq.'43')) lgvalid=.true.
+
+! Madagascar 5R,5S,6X
+ else if(callsign(1:2).eq.'6X') then
+ if((grid(1:2).eq.'LH' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'7').or. &
+ (grid(1:2).eq.'LG' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(1:2).eq.'LH' .and. (grid(3:4).eq.'12' .or. grid(3:4).eq.'47' .or. grid(3:4).eq.'48')) lgvalid=.true.
+
+! Jamaica 6Y
+ else if(callsign(1:2).eq.'6Y') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'17' .or. grid(3:4).eq.'18' .or. grid(3:4).eq.'08' .or. grid(3:4).eq.'06')) &
+ lgvalid=.true.
+
+! Sudan 6T,6U,ST
+ else if(callsign(2:2).eq.'T' .or. callsign(2:2).eq.'U') then
+ if((grid(1:2).eq.'KK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(1:4).eq.'KJ79') lgvalid=.true.
+
+! Pakistan 6P..6S, AP..AS
+ else if(callsign(2:2).gt.'O' .and. callsign(2:2).lt.'T') then
+ if((grid(1:2).eq.'MM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'30' .or. grid(3:4).eq.'31' .or. grid(3:4).eq.'84' .or. grid(3:4).eq.'85')) .or. &
+ (grid(1:2).eq.'ML' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'33'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'MM' .and. grid(3:3).eq.'4' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'7') then; lgvalid=.false.
+ else if(grid(1:2).eq.'ML' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8') .or. &
+ grid(3:4).eq.'07')) then; lgvalid=.false.
+ endif
+endif
+
+! Liberia 5L,5M,6Z,A8,D5,EL
+ else if(callsign(1:2).eq.'6Z') then
+ if(grid(1:2).eq.'IJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'3' .and.grid(4:4).lt.'9'.and. &
+ grid(3:4).ne.'67' .and. grid(3:4).ne.'67') lgvalid=.true.
+
+ endif ! '6'
+
+ else if(callsign(1:1).eq.'7') then
+
+! Indonesia 7A..7I, 8A..8I, PK..PO, YB..YH
+ if(callsign(1:1).eq.'7' .and. callsign(2:2).gt.'@' .and. callsign(2:2).lt.'J') then
+ if((grid(1:2).eq.'NJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NI' .and. grid(3:3).gt.'8' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'OI' .and. .not.(grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'4') &
+ .and. .not.(grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'PI' .and. .not.(grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'OJ' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'PJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'QI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'PH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4) .lt.'6') .or. &
+ (grid(3:3).eq.'7' .and. ((grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. grid(4:4).eq.'0' .or. grid(4:4).eq.'1' .or. &
+ grid(4:4).eq.'3')) .or. (grid(3:3).eq.'8' .and. grid(4:4).gt.'5'.and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ' .and. ((grid(3:3).gt.'4'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OI' .and. ((grid(4:4).eq.'1' .and. grid(3:3).gt.'1'.and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'2'.and. grid(3:3).lt.'6') .or. &
+ grid(3:4).eq.'44' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PI' .and. (grid(3:4).eq.'61' .or.grid(3:4).eq.'62'.or.grid(3:4).eq.'71'.or.grid(3:4).eq.'83'.or. &
+ grid(3:4).eq.'25' .or. grid(3:4).eq.'35' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'44' .or.grid(3:4).eq.'29')) then
+ lgvalid=.false.
+ endif
+endif
+
+! Japan 7J..7N,8J..8N,JA,JE..JS
+ else if(callsign(1:1).eq.'7' .and. callsign(2:2).gt.'I' .and. callsign(2:2).lt.'O') then
+ if((grid(1:2).eq.'PM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'QM0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'QN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6').or. &
+ (grid(1:3).eq.'PN9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'QM19' .or. grid(1:4).eq.'KC90') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and.grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3'.and.grid(3:4).ne.'62').or. &
+ grid(3:4).eq.'45' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'55' .or. grid(3:4).eq.'56' .or.grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'89')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PL'.and.((grid(3:3).gt.'0'.and.grid(3:3).lt.'3'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'38' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'57' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'QN'.and.((grid(3:3).eq.'2'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'1'.or.grid(4:4).eq.'5')).or. &
+ grid(3:4).eq.'10')) then; lgvalid=.false.
+ endif
+endif
+
+! Yemen 7O
+ else if(callsign(1:2).eq.'7O') then
+ if(grid(1:2).eq.'LK' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'7' .and.grid(4:4).gt.'2'.and.grid(4:4).lt.'9').or. &
+ grid(3:4).eq.'05' .or. grid(3:4).eq.'06' .or. grid(3:4).eq.'12' .or. grid(3:4).eq.'22')) lgvalid=.true.
+
+! Lesotho 7P
+ else if(callsign(1:2).eq.'7P') then
+ if((grid(1:2).eq.'KG' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'KF' .and. (grid(3:4).eq.'39' .or. grid(3:4).eq.'49'))) lgvalid=.true.
+
+! Malawi 7Q
+ else if(callsign(1:2).eq.'7Q') then
+ if((grid(1:2).eq.'KH' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'KI60' .or. (grid(1:3).eq.'KH7' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5')) lgvalid=.true.
+
+! Sweden 7S,8S,SA..SM
+ else if(callsign(1:2).eq.'7S') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JP' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'KP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'25'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JO' .and. (grid(3:4).eq.'85' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'JP' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. grid(3:4).eq.'89' .or. &
+ grid(3:4).eq.'99')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. (grid(3:4).eq.'13' .or. grid(3:4).eq.'14')) then; lgvalid=.false.
+ endif
+endif
+
+! Algeria 7R, 7T..7Y
+ else if(callsign(1:2).eq.'7R' .or. callsign(2:2).gt.'S' .and. callsign(2:2).lt.'Z') then
+ if((grid(1:2).eq.'JM' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'5'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'7').or. &
+ grid(3:4).eq.'37') .and. grid(3:4).ne.'43') .or. &
+ (grid(1:2).eq.'IM' .and. ((grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'6').or. &
+ grid(3:4).eq.'70')) .or. &
+ (grid(1:2).eq.'JL' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ grid(3:3).eq.'5' .and. grid(3:3).lt.'1' .and. grid(4:4).eq.'5')) .or. &
+ (grid(1:2).eq.'IL' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2' .and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'92')) .or. &
+ (grid(1:2).eq.'JK' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'4' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'IL' .and. ((grid(3:3).eq.'5' .and. grid(3:3).lt.'2' .and. grid(4:4).eq.'6') .or. &
+ grid(3:4).eq.'63' .or. grid(3:4).eq.'64' .or. grid(3:4).eq.'73')) lgvalid=.false.
+endif
+
+! Saudi Arabia 7Z,8Z,HZ
+ else if(callsign(1:2).eq.'7Z') then
+ if((grid(1:2).eq.'LL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8').or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'5' .and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ (grid(1:2).eq.'KM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KM92') lgvalid=.true.
+
+ endif ! '7'
+
+ else if(callsign(1:1).eq.'8') then
+
+! Indonesia 7A..7I, 8A..8I, PK..PO, YB..YH
+ if(callsign(1:1).eq.'8' .and. callsign(2:2).gt.'@' .and. callsign(2:2).lt.'J') then
+ if((grid(1:2).eq.'NJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NI' .and. grid(3:3).gt.'8' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'OI' .and. .not.(grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'4') &
+ .and. .not.(grid(3:3).gt.'1' .and. grid(3:3).lt.'8' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'PI' .and. .not.(grid(3:3).gt.'3' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0')) .or. &
+ (grid(1:2).eq.'OJ' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'PJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(1:2).eq.'QI' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'1' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. &
+ (grid(1:2).eq.'PH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).eq.'9')) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'1' .and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NJ' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'/' .and. grid(4:4) .lt.'6') .or. &
+ (grid(3:3).eq.'7' .and. ((grid(4:4).gt.'5' .and. grid(4:4).lt.':') .or. grid(4:4).eq.'0' .or. grid(4:4).eq.'1' .or. &
+ grid(4:4).eq.'3')) .or. (grid(3:3).eq.'8' .and. grid(4:4).gt.'5'.and. grid(4:4).lt.':') .or. &
+ grid(3:4).eq.'43' .or. grid(3:4).eq.'44' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OJ' .and. ((grid(3:3).gt.'4'.and.grid(3:3).lt.'7'.and.grid(4:4).gt.'1'.and.grid(4:4).lt.'5').or. &
+ (grid(3:3).eq.'1' .and. grid(4:4).gt.'1' .and. grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'24' .or. grid(3:4).eq.'04')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'OI' .and. ((grid(4:4).eq.'1' .and. grid(3:3).gt.'1'.and. grid(3:3).lt.'5') .or. &
+ (grid(4:4).eq.'5' .and. grid(3:3).gt.'2'.and. grid(3:3).lt.'6') .or. &
+ grid(3:4).eq.'44' .or. grid(3:4).eq.'39')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PI' .and. (grid(3:4).eq.'61' .or.grid(3:4).eq.'62'.or.grid(3:4).eq.'71'.or.grid(3:4).eq.'83'.or. &
+ grid(3:4).eq.'25' .or. grid(3:4).eq.'35' .or. grid(3:4).eq.'34' .or. grid(3:4).eq.'44' .or.grid(3:4).eq.'29')) then
+ lgvalid=.false.
+ endif
+endif
+
+! Japan 7J..7N,8J..8N,JA,JE..JS
+ else if(callsign(1:1).eq.'8' .and. callsign(2:2).gt.'I' .and. callsign(2:2).lt.'O') then
+ if((grid(1:2).eq.'PM' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:3).eq.'QM0' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'QN' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'6').or. &
+ (grid(1:3).eq.'PN9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3') .or. &
+ (grid(1:2).eq.'PL' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'QM19' .or. grid(1:4).eq.'KC90') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'PM' .and. ((grid(3:3).gt.'3' .and. grid(3:3).lt.'8' .and.grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ (grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'3'.and.grid(3:4).ne.'62').or. &
+ grid(3:4).eq.'45' .or. grid(3:4).eq.'46' .or. grid(3:4).eq.'55' .or. grid(3:4).eq.'56' .or.grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'89')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'PL'.and.((grid(3:3).gt.'0'.and.grid(3:3).lt.'3'.and.grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'38' .or. grid(3:4).eq.'39' .or. grid(3:4).eq.'57' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'QN'.and.((grid(3:3).eq.'2'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'1'.or.grid(4:4).eq.'5')).or. &
+ grid(3:4).eq.'10')) then; lgvalid=.false.
+ endif
+endif
+
+! Botswana 8O,A2
+ else if(callsign(1:2).eq.'8O') then
+ if((grid(1:2).eq.'KG' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KH' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2') .or. &
+ (grid(1:2).eq.'KH' .and. (grid(3:4).eq.'22' .or. grid(3:4).eq.'30')) .or. &
+ (grid(1:2).eq.'KG' .and. (grid(3:4).eq.'48' .or. grid(3:4).eq.'47'))) lgvalid=.true.
+
+! Barbados 8P
+ else if(callsign(1:2).eq.'8P' .and. grid(1:4).eq.'GK03') then
+ lgvalid=.true.
+
+! Maldives 8Q
+ else if(callsign(1:2).eq.'8Q') then
+ if((grid(1:3).eq.'MJ6' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'8') .or. grid(1:4).eq.'MI69') lgvalid=.true.
+
+! Guyana 8R
+ else if(callsign(1:2).eq.'8R') then
+ if((grid(1:2).eq.'GJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'0'.and.grid(4:4).lt.'9').or. &
+ (grid(1:3).eq.'FJ9' .and. grid(4:4).gt.'3' .and. grid(4:4).lt.'8')) lgvalid=.true.
+
+! Sweden 7S,8S,SA..SM
+ else if(callsign(1:2).eq.'8S') then
+ if((grid(1:2).eq.'JO' .and. grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'JP' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'9').or. &
+ (grid(1:2).eq.'KP' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'25'))) lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'JO' .and. (grid(3:4).eq.'85' .or. grid(3:4).eq.'95')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'JP' .and. ((grid(3:3).eq.'6' .and. grid(4:4).gt.'4' .and. grid(4:4).lt.'9') .or. &
+ (grid(3:3).eq.'7' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.'9') .or. grid(3:4).eq.'89' .or. &
+ grid(3:4).eq.'99')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'KP' .and. (grid(3:4).eq.'13' .or. grid(3:4).eq.'14')) then; lgvalid=.false.
+ endif
+endif
+
+! India 8T..8Y,AT..AW,VT..VW
+ else if(callsign(2:2).gt.'S' .and. callsign(2:2).lt.'Z') then
+ if((grid(1:2).eq.'MJ' .and. (grid(3:4).eq.'99' .or. grid(3:4).eq.'89' .or. grid(3:4).eq.'88' .or. &
+ grid(3:4).eq.'68')).or. &
+ (grid(1:2).eq.'MK' .and. ((grid(3:3).gt.'5'.and.grid(3:3).lt.':').or.grid(3:4).eq.'51'.or.grid(3:4).eq.'52')).or. &
+ (grid(1:2).eq.'NK' .and. ((grid(3:3).eq.'0' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'6') .or. &
+ (grid(3:3).gt.'/' .and. grid(3:3).lt.'3' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or.grid(3:4).eq.'39')).or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'NL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(1:4).eq.'NM00') lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'MK' .and. grid(3:3).eq.'6' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.'5') then; lgvalid=.false.
+ else if(grid(1:2).eq.'NK' .and. (grid(3:4).eq.'26' .or. grid(3:4).eq.'27')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'ML' .and. ((grid(3:3).gt.'4'.and.(grid(4:4).eq.'0'.or.grid(4:4).eq.'5'.or.grid(4:4).eq.'8'.or. &
+ grid(4:4).eq.'9')) .or. grid(3:4).eq.'58' .or. grid(3:4).eq.'59')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'NL' .and. ((grid(4:4).eq.'9' .and. grid(3:3).gt.'/' .and. grid(4:4).lt.'5') .or. &
+ (grid(4:4).eq.'8' .and. grid(3:3).gt.'0' .and. grid(4:4).lt.'5') .or.grid(3:4).eq.'40')) then; lgvalid=.false.
+ else if(grid(1:2).eq.'MM' .and. (grid(3:4).eq.'61' .or. grid(3:4).eq.'62')) then; lgvalid=.false.
+ endif
+endif
+
+! Saudi Arabia 7Z,8Z,HZ
+ else if(callsign(1:2).eq.'8Z') then
+ if((grid(1:2).eq.'LL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8').or. &
+ (grid(1:2).eq.'KL' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'8' .and. grid(4:4).gt.'5' .and.grid(4:4).lt.':') .or. &
+ (grid(1:2).eq.'LM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'01' .or. grid(3:4).eq.'10')) .or. &
+ (grid(1:2).eq.'KM' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and.grid(4:4).lt.'2') .or. &
+ grid(1:4).eq.'KM92') lgvalid=.true.
+
+ endif ! '8'
+
+ else if(callsign(1:1).eq.'9') then
+
+! Croatia 9A
+ if(callsign(1:2).eq.'9A') then
+ if(grid(1:2).eq.'JN' .and. ((grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and.grid(4:4).gt.'1'.and.grid(4:4).lt.'6').or. &
+ grid(3:4).eq.'64' .or. grid(3:4).eq.'65' .or. grid(3:4).eq.'76' .or. grid(3:4).eq.'86') .and. grid(3:4).ne.'93') &
+ lgvalid=.true.
+
+! Malta 9H
+ else if(callsign(1:2).eq.'9H') then
+ if(grid(1:2).eq.'JM' .and. (grid(3:4).eq.'75' .or. grid(3:4).eq.'76')) lgvalid=.true.
+
+! West Malaysia, East Malaysia 9M,9W
+ else if(callsign(1:2).eq.'9M' .or. callsign(1:2).eq.'9W') then
+ if(grid(1:4).eq.'NJ96' .or. (grid(1:2).eq.'OJ' .and. &
+ (((grid(3:3).gt.'/' .and. grid(3:3).lt.'2') .or. (grid(3:3).gt.'4' .and.grid(3:3).lt.':')) .and. &
+ grid(4:4).gt.'0'.and.grid(4:4).lt.'7') .or. &
+ grid(3:4).eq.'21' .or. grid(3:4).eq.'22' .or. grid(3:4).eq.'41' .or. grid(3:4).eq.'87')) lgvalid=.true.
+
+! Kuwait 9K
+ else if(callsign(1:2).eq.'9K') then
+ if((grid(1:2).eq.'LL' .and. (grid(3:4).eq.'39' .or. grid(3:4).eq.'49' .or. grid(3:4).eq.'38' .or. &
+ grid(3:4).eq.'48')) .or. &
+ (grid(1:2).eq.'LM' .and. (grid(3:4).eq.'30' .or. grid(3:4).eq.'40'))) lgvalid=.true.
+
+! Singapore 9V,S6
+ else if(callsign(1:2).eq.'9V') then
+ if(grid(1:2).eq.'OJ' .and. (grid(3:4).eq.'11' .or. grid(3:4).eq.'21')) lgvalid=.true.
+
+! Trinidad & Tobago 9Y,9Z
+ else if(callsign(1:2).eq.'9Y' .or. callsign(1:2).eq.'9Z') then
+ if(grid(1:2).eq.'FK' .and. (grid(3:4).eq.'90' .or. grid(3:4).eq.'91')) lgvalid=.true.
+
+! Nepal 9N
+ else if(callsign(1:2).eq.'9N') then
+ if((grid(1:2).eq.'NL' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'5' .and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'NM' .and. (grid(3:4).eq.'00' .or. grid(3:4).eq.'10'))) lgvalid=.true.
+
+! Ghana 9G
+ else if(callsign(1:2).eq.'9G') then
+ if((grid(1:2).eq.'IJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ (grid(1:3).eq.'JJ0' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'IK' .and. grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).eq.'0').or. &
+ (grid(1:4).eq.'JK00' .or. grid(1:4).eq.'JJ84' .or. grid(1:4).eq.'JJ94')) lgvalid=.true.
+
+! Zambia 9I,9J
+ else if(callsign(1:2).eq.'9J' .or. callsign(1:2).eq.'9I') then
+ if((grid(1:2).eq.'KH' .and. grid(3:3).gt.'0' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KI' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'7' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'2').or. &
+ grid(1:4).eq.'KH31') lgvalid=.true.
+
+! Sierra Leone 9L
+ else if(callsign(1:2).eq.'9L') then
+ if((grid(1:2).eq.'IJ' .and. grid(3:3).gt.'2' .and. grid(3:3).lt.'5' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.':').or. &
+ grid(1:4).eq.'IJ46') lgvalid=.true.
+
+! Dem. Rep. of the Congo 9O..9T
+ else if(callsign(2:2).gt.'N' .and. callsign(2:2).lt.'U') then
+ if((grid(1:2).eq.'JI' .and. ((grid(3:3).gt.'5' .and. grid(3:3).lt.'8'.and.grid(4:4).gt.'3'.and.grid(4:4).lt.'6').or. &
+ grid(3:3).gt.'7' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'1'.and.grid(4:4).lt.':') .or. grid(3:4).eq.'81').or. &
+ (grid(1:2).eq.'KI' .and. ((grid(3:3).gt.'/'.and.grid(3:3).lt.'5').or.grid(3:4).eq.'51'.or.grid(3:4).eq.'52')).or. &
+ (grid(1:2).eq.'KJ' .and. ((grid(3:3).gt.'/' .and. grid(3:3).lt.'6'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'25' .or. grid(3:4).eq.'35')) .or. &
+ (grid(1:2).eq.'JJ' .and. ((grid(3:3).gt.'8' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ grid(3:4).eq.'80' .or. grid(3:4).eq.'81' .or. grid(3:4).eq.'95')) .or. &
+ (grid(1:2).eq.'KH' .and. ((grid(3:3).gt.'0' .and. grid(3:3).lt.'5'.and.grid(4:4).gt.'7'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'37' .or. grid(3:4).eq.'47' .or. grid(3:4).eq.'46'))) lgvalid=.true.
+
+! Burundi 9U
+ else if(callsign(1:2).eq.'9U') then
+ if(grid(1:2).eq.'KI' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.'8') &
+ lgvalid=.true.
+
+! Rwanda 9X
+ else if(callsign(1:2).eq.'9X') then
+ if(grid(1:2).eq.'KI' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'6' .and. grid(4:4).gt.'6'.and.grid(4:4).lt.'9') &
+ lgvalid=.true.
+
+! Spratly Islands 1S,9M0,BM9S,BN9S,BO9S,BP9S,BQ9S,BU9S,BV9S,BW9S,BX9S
+ else if(callsign(1:3).eq.'9M0') then
+ if((grid(1:2).eq.'OK' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'2').or. &
+ (grid(1:2).eq.'OJ' .and. grid(3:3).gt.'3' .and. grid(3:3).lt.'9' .and. grid(4:4).gt.'6' .and. grid(4:4).lt.':')) &
+ lgvalid=.true.
+
+! Iran 9B..9D,EP,EQ
+ else if(callsign(2:2).gt.'A' .and. callsign(2:2).lt.'E') then
+ if((grid(1:2).eq.'LM' .and. grid(3:3).gt.'1' .and. grid(3:3).lt.':') .or. &
+ (grid(1:2).eq.'LL' .and. ((grid(3:3).gt.'4' .and. grid(3:3).lt.':'.and.grid(4:4).gt.'5'.and.grid(4:4).lt.':').or. &
+ grid(3:4).eq.'49' .or. grid(3:4).eq.'75' .or. grid(3:4).eq.'85' .or. grid(3:4).eq.'95')) .or. &
+ (grid(1:2).eq.'ML' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'4'.and.grid(4:4).lt.':'.and. &
+ grid(3:4).ne.'15' .and. grid(3:4).ne.'19') .or. &
+ (grid(1:2).eq.'MM' .and. grid(3:3).eq.'0' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'7')) &
+ lgvalid=.true.
+
+if(lgvalid) then
+ if(grid(1:2).eq.'LM' .and. ((grid(3:3).eq.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'4') .or. &
+ (grid(3:3).gt.'4' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'7'.and.grid(4:4).lt.':' .and. &
+ grid(3:4).ne.'78' .and. grid(3:4).ne.'88'))) lgvalid=.false.
+endif
+
+! Ethiopia 9E,9F,ET
+ else if(callsign(1:2).eq.'9E' .or. callsign(1:2).eq.'9F') then
+ if((grid(1:2).eq.'LJ' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'4' .and. grid(4:4).gt.'3'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'LK' .and. grid(3:3).gt.'/' .and. grid(3:3).lt.'2' .and. grid(4:4).gt.'/'.and.grid(4:4).lt.'5').or. &
+ (grid(1:2).eq.'KJ' .and. grid(3:3).gt.'5' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'2'.and.grid(4:4).lt.':').or. &
+ (grid(1:2).eq.'KK' .and. grid(3:3).gt.'6' .and. grid(3:3).lt.':' .and. grid(4:4).gt.'/' .and. grid(4:4).lt.'5')) &
+ lgvalid=.true.
+
+ endif ! '9'
+
+ endif ! end of block 1..9
+endif
+
+ return
+end subroutine chkgridvar
diff --git a/lib/ft8var/chklong8.f90 b/lib/ft8var/chklong8.f90 new file mode 100755 index 00000000..5f07c627 --- /dev/null +++ b/lib/ft8var/chklong8.f90 @@ -0,0 +1,46 @@ +subroutine chklong8(callsign,falsedec)
+
+ parameter (NMASK10=9,NMASK11=7)
+ character callsign*12,callmask*12
+ logical(1) falsedec
+ character*12 mask10(NMASK10),mask11(NMASK11)
+ data mask10/'0011000000 ','0011100000 ','0011110000 ','1011000000 ','1011100000 ','1011110000 ', &
+ '0010000000 ','1010000000 ','0110000000 '/
+ data mask11/'00111000000 ','00111100000 ','10111000000 ','10111100000 ','00100000000 ','01100000000 ','10100000000 '/
+
+! <...> I78PY2MTFLF RR73
+! <...> CM5XFIVGPIP RR73
+! WG0XC120LS9 <...> RR73
+! <...> A7MNPJDX/QO RRR TODO list
+! CQ P2PSR6UWBHS
+
+!valid masks for 11-char callsign:
+! DL2019ABCDE TC630ABCDEF 9A200ABCDEF 9A2019ABCDE ZW5STAYHOME Z39STAYHOME 5B4STAYHOME
+! 00111100000 00111000000 10111000000 10111100000 00100000000 01100000000 10100000000
+ callmask=''
+! need to exclude 8J/8N/8K Japanese callsigns from checking
+ if(index(callsign,'/').lt.1 .and. callsign(1:2).ne.'8J' .and. callsign(1:2).ne.'8N') then
+ if(len_trim(callsign).eq.10) then
+ do i=1,10
+ if(callsign(i:i).gt.'/' .and. callsign(i:i).lt.':') then; callmask(i:i)='1'; else; callmask(i:i)='0'; endif
+ enddo
+!print *,callsign,callmask
+ falsedec=.true.
+ do i=1,NMASK10
+ if(callmask.eq.mask10(i)) then; falsedec=.false.; return; endif
+ enddo
+ endif
+ if(len_trim(callsign).eq.11) then
+ do i=1,11
+ if(callsign(i:i).gt.'/' .and. callsign(i:i).lt.':') then; callmask(i:i)='1'; else; callmask(i:i)='0'; endif
+ enddo
+!print *,callsign,callmask
+ falsedec=.true.
+ do i=1,NMASK11
+ if(callmask.eq.mask11(i)) then; falsedec=.false.; return; endif
+ enddo
+ endif
+ endif
+
+ return
+end subroutine chklong8
diff --git a/lib/ft8var/chkspecial8var.f90 b/lib/ft8var/chkspecial8var.f90 new file mode 100755 index 00000000..55c58303 --- /dev/null +++ b/lib/ft8var/chkspecial8var.f90 @@ -0,0 +1,41 @@ +
+subroutine chkspecial8var(msg37,msg37_2,nbadcrc)
+
+ use ft8_mod1, only : mycall,hiscall
+ character msg37*37,msg37_2*37,call_a*12,call_b*12,call_c*12
+ logical(1) falsedec
+
+ call_a=' '; call_b=' '; call_c=' '
+
+! V03VTJ RR73; 2D3VDY <...> +08 call_a call_b call_c
+!V03VTJ <...> RR73
+!2D3VDY <...> +08
+! Y84NN RR73; HO5RFG <...> -16
+!Y84NN <...> RR73
+!HO5RFG <...> -16
+! P7IJQ RR73; MP4LEL <...> +02
+!P7IJQ <...> RR73
+!MP4LEL <...> +02
+
+ ispc1=index(msg37,' '); ispc2=index(msg37((ispc1+1):),' ')+ispc1; ispc12=index(msg37_2,' ')
+ if(ispc1.gt.3 .and. ispc2.gt.7) then
+ call_a=msg37(1:ispc1-1); call_b=msg37_2(1:ispc12-1); call_c=msg37(ispc1+1:ispc2-1)
+ if(call_a.ne.mycall .and. call_b.ne.mycall .and. call_c.ne.hiscall) then
+! call may not start from 'Q', zero and two digits
+ if(call_a(1:1).eq.'Q' .or. call_b(1:1).eq.'Q') then
+ nbadcrc=1; msg37=' '; msg37_2=msg37; return; endif
+ if(call_a(1:1).eq.'0' .or. call_b(1:1).eq.'0') then
+ nbadcrc=1; msg37=' '; msg37_2=msg37; return; endif
+ if(call_a(1:1).ge.'0' .and. call_a(1:1).le.'9' .and. call_a(2:2).ge.'0' .and. call_a(2:2).le.'9') then
+ nbadcrc=1; msg37=' '; msg37_2=msg37; return; endif
+ if(call_b(1:1).ge.'0' .and. call_b(1:1).le.'9' .and. call_b(2:2).ge.'0' .and. call_b(2:2).le.'9') then
+ nbadcrc=1; msg37=' '; msg37_2=msg37; return; endif
+
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) then; nbadcrc=1; msg37=' '; msg37_2=msg37; return; endif
+ endif
+ endif
+
+ return
+end subroutine chkspecial8var
diff --git a/lib/ft8var/cwfilter.f90 b/lib/ft8var/cwfilter.f90 new file mode 100755 index 00000000..d8a6404d --- /dev/null +++ b/lib/ft8var/cwfilter.f90 @@ -0,0 +1,180 @@ +subroutine cwfilter(first)
+
+ use ft8_mod1, only : cw,windowc1,windowx,pivalue,facx,mcq,m73,mrr73,mrrr,one,twopi,facc1,dt,csync,idtone25,csynccq, &
+ NFILT1,NFILT2,endcorr,ctwkw,ctwkn,ctwk256
+ use jt65_mod9 ! callsign DB to memory
+ use prog_args ! path to files
+
+ parameter (NFFT=180000)
+ complex csig0(151680)
+ real*4 window1(-NFILT1/2:NFILT1/2),window2(-NFILT2/2:NFILT2/2)
+ character*37 msgcq25(25),msgsent37
+ integer itone(79)
+ integer*1 msgbits(77)
+ logical, intent(in) :: first
+
+!pushing callsigns from ALLCALL to memory
+!note that with new, larger ALLCALL7.TXT files, dimensions of various ncall arrays may need to be increased in jt65_mod9.f90
+!on 20250709 callj dim was increased from 9000 to 10000 when updated ALLCALL7.TXT file was added
+ if(first) then
+ open(24,file='ALLCALL7.TXT',status='unknown') ! accepting Australian 7-char callsigns
+ do i=1,MAXC
+ read(24,1004,end=20) line
+1004 format(a80)
+ if(line(1:4).eq.'ZZZZ') exit
+ if(line(1:2).eq.'//') cycle
+ i1=index(line,',')
+ if(i1.lt.4 .or. i1.gt.8) cycle
+ callsign=line(1:i1-1)
+ if(callsign(1:1).gt.'0' .and. callsign(1:1).lt.'D') then; ncall0c=ncall0c+1; call0c(ncall0c)=callsign(1:7)
+ else if(callsign(1:1).gt.'C' .and. callsign(1:1).lt.'E') then; ncalld=ncalld+1; calld(ncalld)=callsign(1:7)
+ else if(callsign(1:1).gt.'D' .and. callsign(1:1).lt.'G') then; ncallef=ncallef+1; callef(ncallef)=callsign(1:7)
+ else if(callsign(1:1).gt.'F' .and. callsign(1:1).lt.'I') then; ncallgh=ncallgh+1; callgh(ncallgh)=callsign(1:7)
+ else if(callsign(1:1).gt.'H' .and. callsign(1:1).lt.'J') then; ncalli=ncalli+1; calli(ncalli)=callsign(1:7)
+ else if(callsign(1:1).gt.'I' .and. callsign(1:1).lt.'K') then; ncallj=ncallj+1; callj(ncallj)=callsign(1:7)
+ else if(callsign(1:1).gt.'J' .and. callsign(1:1).lt.'L') then; ncallk=ncallk+1; callk(ncallk)=callsign(1:7)
+ else if(callsign(1:1).gt.'K' .and. callsign(1:1).lt.'N') then; ncalllm=ncalllm+1; calllm(ncalllm)=callsign(1:7)
+ else if(callsign(1:1).gt.'M' .and. callsign(1:1).lt.'O') then; ncalln=ncalln+1; calln(ncalln)=callsign(1:7)
+ else if(callsign(1:1).gt.'N' .and. callsign(1:1).lt.'P') then; ncallo=ncallo+1; callo(ncallo)=callsign(1:7)
+ else if(callsign(1:1).gt.'O' .and. callsign(1:1).lt.'R') then; ncallpq=ncallpq+1; callpq(ncallpq)=callsign(1:7)
+ else if(callsign(1:1).gt.'Q' .and. callsign(1:1).lt.'S') then; ncallr=ncallr+1; callr(ncallr)=callsign(1:7)
+ else if(callsign(1:1).gt.'R' .and. callsign(1:1).lt.'U') then; ncallst=ncallst+1; callst(ncallst)=callsign(1:7)
+ else if(callsign(1:1).gt.'T' .and. callsign(1:1).lt.'W') then; ncalluv=ncalluv+1; calluv(ncalluv)=callsign(1:7)
+ else if(callsign(1:1).gt.'V' .and. callsign(1:1).lt.'X') then; ncallw=ncallw+1; callw(ncallw)=callsign(1:7)
+ else if(callsign(1:1).gt.'W' .and. callsign(1:1).le.'Z') then; ncallxz=ncallxz+1; callxz(ncallxz)=callsign(1:7)
+ endif
+ enddo
+20 close(24)
+!print *,ncall0c,"call0c"; print *,ncalld,"calld"; print *,ncallef,"callef"; print *,ncallgh,"callgh"
+!print *,ncalli,"calli"; print *,ncallj,"callj"; print *,ncallk,"callk"; print *,ncalllm,"calllm"
+!print *,ncalln,"calln"; print *,ncallo,"callo"; print *,ncallpq,"callpq"; print *,ncallr,"callr"
+!print *,ncallst,"callst"; print *,ncalluv,"calluv"; print *,ncallw,"callw"; print *,ncallxz,"callxz"
+ if(ncall0c.lt.1 .or. ncalld.lt.1 .or. ncallef.lt.1 .or. ncallgh.lt.1 .or. ncalli.lt.1 .or. ncallj.lt.1 .or. &
+ ncallk.lt.1 .or. ncalllm.lt.1 .or. ncalln.lt.1 .or. ncallo.lt.1 .or. ncallpq.lt.1 .or. ncallr.lt.1 .or. &
+ ncallst.lt.1 .or. ncalluv.lt.1 .or. ncallw.lt.1 .or. ncallxz.lt.1) then
+ ldbvalid=.false.
+ write(*,4) 'ALLCALL7.TXT is too short or broken?','d' ! 50th position for "d"
+4 format(a36,13x,a1)
+ call flush(6)
+ endif
+
+ pivalue=4.d0*atan(1.d0)
+ twopi=8.d0*atan(1.d0)
+ dt=1.d0/12000.d0
+
+ do i=0,54; windowc1(i)=(1.0+cos(i*pivalue/55))/2; enddo
+ facx=1.0/300.0
+ do i=0,200
+ windowx(i)=(1.0+cos(i*pivalue/200))/2
+ enddo
+ windowx=facx*windowx
+ facc1=0.01/sqrt(61440.) ! 1.0/sqrt(192000.*3200.) NFFT1*NFFT2
+
+ mcq=2*mcq-1
+ mrrr=2*mrrr-1
+ m73=2*m73-1
+ mrr73=2*mrr73-1
+
+ one=.false.
+ do i=0,511
+ do j=0,8
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
+
+ msgcq25=''
+ msgcq25(2)='CQ 2E0DLA IO92'
+ msgcq25(3)='CQ BH3NEB ON81'
+ msgcq25(4)='CQ CG3CGT FN04'
+ msgcq25(5)='CQ DX CT1JA IM59'
+ msgcq25(6)='CQ CU20E'
+ msgcq25(7)='CQ NA CX1OB GF14'
+ msgcq25(8)='CQ DF2AJ JN49'
+ msgcq25(9)='CQ DG4XPZ JN58'
+ msgcq25(10)='CQ EA8XR IL19'
+ msgcq25(11)='CQ F1YE IN94'
+ msgcq25(12)='CQ DX G1KLN IO82'
+ msgcq25(13)='CQ HL2KVF PM38'
+ msgcq25(14)='CQ IU1ZSV JN45'
+ msgcq25(15)='CQ JG1TWO PM96'
+ msgcq25(16)='CQ K2ST EM96'
+ msgcq25(17)='CQ N9TUX EL98'
+ msgcq25(18)='CQ SA NO2FA FM18'
+ msgcq25(19)='CQ OH6GKE KP13'
+ msgcq25(20)='CQ PD0ORM JO24'
+ msgcq25(21)='CQ DX PT7DS HI06'
+ msgcq25(22)='CQ RA3XEP KO84'
+ msgcq25(23)='CQ SM2GSH KP05'
+ msgcq25(24)='CQ UA9OHX NO15'
+ msgcq25(25)='CQ JA W0YH EN12'
+ do i=2,25
+ i3=-1; n3=-1
+ call genft8sdvar(msgcq25(i),i3,n3,msgsent37,msgbits,itone)
+ if(i.eq.2) then
+ call gen_ft8wave(itone,79,1920,2.0,12000.0,0.0,csig0,xjunk,1,151680)
+ m=1
+ do j=0,14
+ do k=1,32
+ if(j.lt.7) then; csync(j,k)=csig0(m); else; csynccq(j-7,k)=csig0(m); endif
+ m=m+60
+ enddo
+ enddo
+ endif
+ idtone25(i,1:29)=itone(8:36)
+ idtone25(i,30:58)=itone(44:72)
+ enddo
+ dt2=0.005 ! fs2=200 Hz
+ k=1
+ do ifr=-5,5 !Search over +/- 2.5 Hz
+ delf=ifr*0.5
+ dphi=twopi*delf*dt2
+ phi=0.0
+ do i=1,32
+ ctwkw(k,i)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ enddo
+ k=k+1
+ enddo
+ k=1
+ do ifr=-5,5 !Search over +/- 1.25 Hz
+ delf=ifr*0.25
+ dphi=twopi*delf*dt2
+ phi=0.0
+ do i=1,32
+ ctwkn(k,i)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ enddo
+ k=k+1
+ enddo
+! lcqsignal
+ delf=3.125
+ dphi=twopi*delf*dt2
+ phi=0.0
+ do i=1,256
+ ctwk256(i)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ enddo
+ endif
+
+! this filter is being used for signal subtraction
+! Create and normalize the filter
+ if(first) then
+ fac=1.0/float(nfft)
+ sumw=0.0
+ do j=-NFILT1/2,NFILT1/2
+ window1(j)=cos(pivalue*j/NFILT1)**2
+ sumw=sumw+window1(j)
+ enddo
+ cw=0.
+ cw(1:NFILT1+1)=window1/sumw
+ cw=cshift(cw,NFILT1/2+1)
+ do j=1,NFILT1/2+1
+ endcorr(j)=1.0/(1.0-sum(window1(j-1:NFILT1/2))/sumw)
+ enddo
+ call four2avar(cw,NFFT,1,-1,1)
+ cw=cw*fac
+ endif
+
+ return
+end subroutine cwfilter
+
\ No newline at end of file diff --git a/lib/ft8var/datacor.f90 b/lib/ft8var/datacor.f90 new file mode 100755 index 00000000..c0fecebc --- /dev/null +++ b/lib/ft8var/datacor.f90 @@ -0,0 +1,39 @@ +
+subroutine datacor(datapwr,datacorr)
+
+ use jt65_mod2var, only : s3,correct
+
+ real datapwr,datacorr
+
+! calculate information tones power and datapower/syncpower ratio
+ datapwr=0.0
+ do i=1,63
+ datapwr=datapwr+s3(correct(i)+1,i)
+ enddo
+
+! use short correlation function in time and frequency domains
+ timeplus=0.; timeminus=0.; freqplus=0.; freqminus=0.
+ do i=1,63
+ k=i+1
+ m=i-1
+ if(i.eq.1) m=2
+ if(i.eq.63) k=62
+ timeplus=timeplus+s3(correct(i)+1,k)
+ timeminus=timeminus+s3(correct(i)+1,m)
+ if(correct(i).lt.63) then
+ j=1
+ else
+ j=-1
+ endif
+ if(correct(i).gt.1) then
+ n=-1
+ else
+ n=1
+ endif
+ freqplus=freqplus+s3(correct(i)+1+j,i)
+ freqminus=freqminus+s3(correct(i)+1+n,i)
+ enddo
+ datacorr=datapwr*4.0/(timeplus+timeminus+freqplus+freqminus)
+
+ return
+end subroutine datacor
diff --git a/lib/ft8var/encode174_91var.f90 b/lib/ft8var/encode174_91var.f90 new file mode 100755 index 00000000..38c15ee4 --- /dev/null +++ b/lib/ft8var/encode174_91var.f90 @@ -0,0 +1,59 @@ +subroutine encode174_91var(message77,codeword)
+!
+! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword
+!
+use, intrinsic :: iso_c_binding
+use iso_c_binding, only: c_loc,c_size_t
+use crc
+
+integer, parameter:: N=174, K=91, M=N-K
+character*91 tmpchar
+integer*1 codeword(N)
+integer*1 gen(M,K)
+integer*1 message77(77),message(K)
+integer*1 pchecks(M)
+integer*1, target :: i1MsgBytes(12)
+include '/lib/ft8/ldpc_174_91_c_generator.f90'
+logical first
+data first/.true./
+save first,gen
+!$omp threadprivate(first,gen)
+
+if( first ) then ! fill the generator matrix
+ first=.false.
+ gen=0
+ do i=1,M
+ do j=1,23
+ read(g(i)(j:j),"(Z1)") istr
+ ibmax=4
+ if(j.eq.23) ibmax=3
+ do jj=1, ibmax
+ icol=(j-1)*4+jj
+ if( btest(istr,4-jj) ) gen(i,icol)=1
+ enddo
+ enddo
+ enddo
+endif
+
+! Add 14-bit CRC to form 91-bit message+CRC14
+write(tmpchar,'(77i1)') message77
+tmpchar(78:80)='000'
+i1MsgBytes=0
+read(tmpchar,'(10b8)') i1MsgBytes(1:10)
+ncrc14 = crc14 (c_loc (i1MsgBytes), 12)
+write(tmpchar(78:91),'(b14)') ncrc14
+read(tmpchar,'(91i1)') message
+
+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_91var
diff --git a/lib/ft8var/extract_callvar.f90 b/lib/ft8var/extract_callvar.f90 new file mode 100755 index 00000000..4b8e18cf --- /dev/null +++ b/lib/ft8var/extract_callvar.f90 @@ -0,0 +1,28 @@ +
+subroutine extract_callvar(msg37,call2)
+
+ character, intent(in) :: msg37*37
+ character, intent(out) :: call2*12
+ character part2*12,part3*12
+
+ call2=''; part2=''; part3=''
+ ispc1=index(msg37,' '); ispc2=index(msg37((ispc1+1):),' ')+ispc1; ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ part2=msg37(ispc1+1:ispc2-1); part3=msg37(ispc2+1:ispc3-1); npart2len=len_trim(part2)
+
+ if(msg37(1:3).eq.'CQ ' .or. msg37(1:3).eq.'DE ' .or. msg37(1:4).eq.'QRZ ') then
+ if(npart2len.gt.4) then; call2=part2
+ elseif(npart2len.eq.4) then
+ if(part2(2:2).ge.'0' .and. part2(2:2).lt.':' .or. part2(3:3).ge.'0' .and. part2(3:3).lt.':') then; call2=part2
+ else; call2=part3
+ endif
+ elseif(npart2len.eq.3) then
+ if(part2(1:1).ge.'A' .and. part2(1:1).lt.'[' .and. part2(2:2).ge.'0' .and. part2(2:2).lt.':') then; call2=part2
+ else; call2=part3
+ endif
+ elseif(npart2len.eq.2) then; call2=part3
+ endif
+ elseif(ispc1.gt.3 .and. ispc1.lt.13) then; call2=part2
+ endif
+
+ return
+end subroutine extract_callvar
\ No newline at end of file diff --git a/lib/ft8var/filbigvar.f90 b/lib/ft8var/filbigvar.f90 new file mode 100755 index 00000000..191d1d2f --- /dev/null +++ b/lib/ft8var/filbigvar.f90 @@ -0,0 +1,198 @@ +subroutine filbigvar(f0,newfft,c4a,n4,sq0,c6a,n2)
+
+! Filter and downsample the real data in array dd(npts), sampled at 12000 Hz.
+! Output is complex, sampled at 1378.125 Hz.
+
+ use, intrinsic :: iso_c_binding
+ use FFTW3
+ use timer_module, only: timer
+ use jt65_mod5 !ref(3413)
+ use jt65_mod6 !NPTS=624000 dd(NPTS)
+
+ parameter (NFFT1=672000,NFFT2=77175,NFFT3=9646,NSZ=3413)
+ parameter (NZ2=1000)
+
+ real*4 rca(NFFT1)
+ complex ca(NFFT1/2+1) !FFT of input
+ complex c4a(NFFT2),c6a(NFFT3) !Output data
+ real*4 s(NZ2)
+ integer i,j
+ real halfpulse(15),halfpulse2(15) !Impulse response of filter (one sided)
+ complex cfilt(NFFT2),cfilt2(NFFT2) !Filter (complex; imag = 0)
+ real rfilt(NFFT2),rfilt2(NFFT2) !Filter (real)
+ type(C_PTR) :: plan1,plan2,plan3,plan4,plan5 !Pointers to FFTW plans
+ logical first
+ logical(1) newfft
+ equivalence (rfilt,cfilt),(rfilt2,cfilt2),(rca,ca)
+ data first/.true./
+
+! Kaiser-Bessel FIR LPF http://www.arc.id.au/FilterDesign.html
+! fsample (Hz) 12000 Input sample rate
+! Ntaps 29 Number of filter taps
+! fc (Hz) 4353 Cutoff frequency
+! dF/2 (Hz) 328 Half transition band
+! Stop Atten (dB) 30 Stopband attenuation
+! fout (Hz) 1378.125 Output sample rate
+ data halfpulse/0.725500000, 0.240786311, -0.154852552, 0.053941884, 0.022651887, -0.053126870, &
+ 0.041168005, -0.009120071, -0.017722128, 0.025226891, -0.015037961, -0.001056840, 0.011283798, &
+ -0.011212205, 0.004348607/
+
+! Kaiser-Bessel FIR LPF http://www.arc.id.au/FilterDesign.html
+! fsample (Hz) 1378.125 Input sample rate
+! Ntaps 29 Number of filter taps
+! fc (Hz) 86 Cutoff frequency
+! dF/2 (Hz) 38 Half transition band
+! Stop Atten (dB) 30 Stopband attenuation
+! fout (Hz) 172.265625 Output sample rate
+ data halfpulse2/0.124952381, 0.121297716, 0.110774440, 0.094635363, 0.074749989, 0.053318415, &
+ 0.032545585, 0.014332629, 0.000036722, -0.009663997, -0.014785038, -0.015937306, -0.014143718, &
+ -0.010611825, -0.006507996/
+ common/patience/npatience,nthreads
+ save first,plan1,plan2,plan3,plan4,plan5,rfilt,cfilt,rfilt2,cfilt2,ca
+
+ if(f0.lt.0.) go to 900 !Clean up at end of program
+
+ nthreadsmin=nthreads !single JT65 mode
+ if(nnmode.eq.74) then
+ nthreadsmin=max(nthreads-1,1)
+ if(nthreads.ge.8 .and. nthreads.lt.12) nthreadsmin=nthreads-2
+ if(nthreads.ge.12) nthreadsmin=nthreads-3
+ endif
+
+ if(first) then
+ nflags=FFTW_ESTIMATE
+ if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT
+ if(npatience.eq.2) nflags=FFTW_MEASURE
+ if(npatience.eq.3) nflags=FFTW_PATIENT
+ if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE
+
+! Plan the FFTs just once
+ !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
+ call fftwf_plan_with_nthreads(nthreadsmin)
+ plan1=fftwf_plan_dft_r2c_1d(nfft1,rca,ca,nflags)
+ plan2=fftwf_plan_dft_1d(nfft2,c4a,c4a,-1,nflags)
+ plan3=fftwf_plan_dft_1d(nfft2,cfilt,cfilt,+1,nflags)
+ call fftwf_plan_with_nthreads(1)
+ plan4=fftwf_plan_dft_1d(nfft3,cfilt2,cfilt2,+1,nflags)
+ plan5=fftwf_plan_dft_1d(nfft3,c6a,c6a,-1,nflags)
+ !$omp end critical(fftw)
+
+! Convert impulse response to filter function
+ cfilt=0.
+ cfilt2=0.
+ fac=0.00625/nfft1
+ fac2=0.03
+
+ cfilt(1)=fac*halfpulse(1)
+ cfilt2(1)=fac2*halfpulse2(1)
+ do i=2,15
+ cfilt(i)=fac*halfpulse(i)
+ cfilt(nfft2+2-i)=fac*halfpulse(i)
+ enddo
+ do i=2,15
+ cfilt2(i)=fac2*halfpulse2(i)
+ cfilt2(nfft3+2-i)=fac2*halfpulse2(i)
+ enddo
+
+ call fftwf_execute_dft(plan3,cfilt,cfilt)
+ call fftwf_execute_dft(plan4,cfilt2,cfilt2)
+
+ base=real(cfilt(38588)) ! nfft2/2+1
+ base2=real(cfilt2(nfft3/2+1))
+ do i=1,nfft2
+ rfilt(i)=real(cfilt(i))-base
+ enddo
+ do i=1,nfft3
+ rfilt2(i)=real(cfilt2(i))-base2
+ enddo
+ first=.false.
+ endif
+
+! When new data comes along, we need to compute a new "big FFT"
+! If we just have a new f0, continue with the existing data in ca.
+
+ if(newfft) then
+! call timer('FFTbig ',0)
+ rca(1:npts)=dd(1:npts)
+ rca(npts+1:)=0.
+
+ call fftwf_execute_dft_r2c(plan1,rca,ca)
+! call timer('FFTbig ',1)
+
+ ib=0
+ do j=1,NSZ
+ ia=ib+1
+ ib=nint(float(j)*(672000./8192)) ! NFFT1/NFFT
+ if(ref(j).le.0.0) ref(j)=0.0001
+ fac=sqrt(1.0/ref(j))
+ ca(ia:ib)=fac*conjg(ca(ia:ib))
+ enddo
+ endif
+
+! NB: f0 is the frequency at which we want our filter centered.
+! i0 is the bin number in ca closest to f0.
+! call timer('loops ',0)
+ i0=nint(f0*56.) + 1 ! f0/df where delta f = 12000/672000 = 1/56
+ nh=38587 ! nfft2/2
+
+ do i=1,nh !Copy data into c4a and apply
+ j=i0+i-1 !the filter function
+ if(j.ge.1 .and. j.le.nfft1/2+1) then
+ c4a(i)=rfilt(i)*ca(j)
+ else
+ c4a(i)=0.
+ endif
+ enddo
+ do i=nh+1,nfft2
+ j=i0+i-1-nfft2
+ if(j.ge.1) then
+ c4a(i)=rfilt(i)*ca(j)
+ else
+ c4a(i)=rfilt(i)*conjg(ca(2-j))
+ endif
+ enddo
+
+ nh=nfft3/2
+ do i=1,nh
+ c6a(i)=rfilt2(i)*c4a(i)
+ enddo
+ do i=nh+1,nfft3
+ c6a(i)=rfilt2(i)*c4a(nfft2-nfft3+i)
+ enddo
+
+ nadd=nfft2/(3.0*NZ2) ! 180Hz BW
+
+ i=0
+ do j=1,NZ2
+ s(j)=0.
+ do n=1,nadd
+ i=i+1
+ s(j)=s(j) + real(c4a(i))**2 + aimag(c4a(i))**2
+ enddo
+ enddo
+ call pctile(s,NZ2,10,sq0)
+ sq0=sq0*1.732 ! SQRT(3.0)
+! call timer('loops ',1)
+
+! Do the short reverse transform, to go back to time domain.
+! call timer('FFTsmall',0)
+ call fftwf_execute_dft(plan2,c4a,c4a)
+ call fftwf_execute_dft(plan5,c6a,c6a)
+! call timer('FFTsmall',1)
+ n4=min(npts/8,nfft2)
+ n2=nfft3
+
+ return
+
+900 continue
+
+ !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
+ call fftwf_destroy_plan(plan1)
+ call fftwf_destroy_plan(plan2)
+ call fftwf_destroy_plan(plan3)
+ call fftwf_destroy_plan(plan4)
+ call fftwf_destroy_plan(plan5)
+ !$omp end critical(fftw)
+
+ return
+end subroutine filbigvar
diff --git a/lib/ft8var/fillhashvar.f90 b/lib/ft8var/fillhashvar.f90 new file mode 100755 index 00000000..be4453be --- /dev/null +++ b/lib/ft8var/fillhashvar.f90 @@ -0,0 +1,68 @@ +subroutine fillhashvar(numthreads,lfill)
+
+ use packjt77var ! also setting mycall13,dxcall13
+ use ft8_mod1, only : mycall,hiscall
+ integer, intent(in) :: numthreads
+ logical, intent(in) :: lfill
+ character*13 cw
+
+ if(lfill) then
+ do i=1,numthreads
+ do m=1,nlast_calls(i)
+ nposition=nthrindex(i)+m
+ cw=last_calls(nposition)
+!print *,i,m,cw
+ n10=ihashcall(cw,10)
+ if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) calls10(n10)=cw
+
+ n12=ihashcall(cw,12)
+ if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) calls12(n12)=cw
+
+ n22=ihashcall(cw,22)
+ if(any(ihash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one
+ where(ihash22.eq.n22) calls22=cw
+ go to 900
+ endif
+
+! New entry: move table down, making room for new one at the top
+ ihash22(nzhash:2:-1)=ihash22(nzhash-1:1:-1)
+
+! Add the new entry
+ calls22(nzhash:2:-1)=calls22(nzhash-1:1:-1)
+ ihash22(1)=n22
+ calls22(1)=cw
+ if(nzhash.lt.MAXHASH) nzhash=nzhash+1
+900 continue
+ enddo
+ enddo
+ else
+ nlast_calls=0
+ mycall13=mycall//' '; dxcall13=hiscall//' '
+ if(mycall13.ne.mycall13_0) then
+ if(len(trim(mycall13)).gt.2) then
+ mycall13_set=.true.
+ mycall13_0=mycall13
+ call save_hash_mycallvar(mycall13,hashmy10,hashmy12,hashmy22)
+!print *,mycall13,hashmy10,hashmy12,hashmy22
+ else
+ mycall13_set=.false.
+ endif
+ endif
+
+ if(dxcall13.ne.dxcall13_0) then
+ if(len(trim(dxcall13)).gt.2) then
+ dxcall13_set=.true.
+ dxcall13_0=dxcall13
+ hashdx10=ihashcall(dxcall13,10)
+! make sure new DX Call is stored in hash tables prior to decoding
+! it is needed if manually callsign set in DX Call window was not decoded before
+ call save_hash_callvar(dxcall13,1)
+!print *,dxcall13,hashdx10
+ else
+ dxcall13_set=.false.
+ endif
+ endif
+ endif
+
+ return
+end subroutine fillhashvar
diff --git a/lib/ft8var/filtersfreevar.f90 b/lib/ft8var/filtersfreevar.f90 new file mode 100755 index 00000000..ac04b23d --- /dev/null +++ b/lib/ft8var/filtersfreevar.f90 @@ -0,0 +1,126 @@ +
+subroutine filtersfreevar(decoded,falsedec)
+
+ real datacorr
+ character decoded*22,d1*1,d2*2,d3*3,d4*4,d5*5
+ logical(1) falsedec
+
+ ndot=0
+ nsign=0
+ nother=0
+
+ if(decoded(11:12).eq.'73') go to 4
+ if(decoded(12:13).eq.'73') go to 4
+ if(decoded(1:1).eq.'/') go to 2
+
+ do i=1,13
+ d1=decoded(i:i); d2=decoded(i:(i+1)); d3=decoded(i:(i+2)); d4=decoded(i:(i+3)); d5=decoded(i:(i+4))
+ if(d2.eq.'73' .or. d2.eq.'TU' .or. d2.eq.'GL') go to 4
+! HA8QJ -07 HA8QJ R-07
+ if(i.gt.4) then
+ if((d2.eq.' -' .or. d2.eq.' +') .and. decoded(i+2:i+2).ge.'0' .and. decoded(i+2:i+2).lt.'3') go to 4
+ if((d3.eq.' R-' .or. d3.eq.' R+') .and. decoded(i+3:i+3).ge.'0' .and. decoded(i+3:i+3).lt.'3') go to 4
+ endif
+ if(d3.eq.'QSL' .or. d3.eq.'TNX' .or. d2.eq.'RR' .or. &
+ d3.eq.'QSO' .or. d3.eq.'CFM' .or. d4.eq.'LOTW' .or. &
+ d3.eq.'BND' .or. d3.eq.'QSY' .or. d4.eq.'BAND') go to 4
+ if(d3.eq.'MAS' .or. d3.eq.'HNY' .or. d3.eq.'HPY' .or. d3.eq.' DT' .or. &
+ d3.eq.'XMS' .or. d5.eq.'EASTE' .or. d5.eq.'PIRAT' .or. d4.eq.'TEST') go to 4
+ if(d5.eq.'/HYBR' .or. d5.eq.'/HTML' .or. d5.eq.'/PHOT' .or. d5.eq.'/IMAG' .or. d5.eq.'/JOIN' .or. d5.eq.'QRZ.C' &
+ .or. d4.eq.'/GIF' .or. d4.eq.'/JPG' .or. d4.eq.'/AVI' .or. d4.eq.'/MP4' .or. d4.eq.'/CMD') go to 4
+ if(d1.eq.'.') ndot=ndot+1
+ if(d1.eq.'-' .or. d1.eq.'+' .or. d1.eq.'?') nsign=nsign+1
+ if(d1.eq.'/' .or. d1.eq.'?') nother=nother+1
+ enddo
+
+ if(ndot.ge.2 .or. nsign.ge.2 .or. nother.ge.2) go to 2
+ if(decoded(1:2).eq.'-0') go to 2
+ if(decoded(1:1).ne.' ' .and. decoded(2:2).eq.' ') go to 2
+
+ if(((decoded(13:13).ge.'A' .and. decoded(13:13).le.'Z') .or. &
+ (decoded(13:13).ge.'0' .and. decoded(13:13).le.'9')) .and. &
+ decoded(12:12).eq.' ') go to 2
+
+ if(decoded(1:1).eq.'.' .or. decoded(1:1).eq.'+' .or. decoded(1:1).eq.'?' &
+ .or. decoded(1:1).eq.'/' .or. decoded(13:13).eq.'.' .or. decoded(13:13).eq.'+' &
+ .or. decoded(13:13).eq.'-' .or. decoded(13:13).eq.'/') go to 2
+
+ if(decoded(2:2).eq.'-' .or. decoded(2:2).eq.'+' .or. decoded(12:12).eq.'.' .or. &
+ decoded(12:12).eq.'+' .or. decoded(12:12).eq.'-') go to 2
+
+ if(decoded(12:12).ge.'0' .and. decoded(12:12).le.'9' .and. &
+ decoded(13:13).ge.'0' .and. decoded(13:13).le.'9') then
+
+ if(decoded(12:13).ne.'55' .and. decoded(12:13).ne.'73' .and. decoded(12:13).ne.'88') go to 2
+
+ endif
+
+ if(decoded(1:1).eq.'0' .and. decoded(2:2).ne.'.') go to 2
+
+ do i=1,12
+ if(i.lt.12 .and. decoded(i:i).eq."?" .and. decoded(i+1:i+1).ne." ") go to 2
+ if(i.lt.12 .and. decoded(i:i).ne." " .and. decoded(i+1:i+1).eq."+" &
+ .and. (decoded(i+2:i+2).le."0" .or. decoded(i+2:i+2).ge."9")) go to 2
+
+ if(decoded(i:i).ge.'A' .and. decoded(i:i).le.'Z' .and. decoded(i+1:i+1).eq.'.' .and. &
+ decoded(i+2:i+2).ge.'A' .and. decoded(i+2:i+2).le.'Z') go to 2
+
+ if(decoded(i+1:i+2).eq.'/ ' .or. decoded(i+1:i+2).eq.' /') go to 2
+
+ if(decoded(i:i).ge.'0' .and. decoded(i:i).le.'9' .and. decoded(i+1:i+1).eq.'/' .and. &
+ decoded(i+2:i+2).ge.'0' .and. decoded(i+2:i+2).le.'9') go to 2
+
+ if(decoded(i:i).eq.' ' .and. decoded(i+1:i+1).ge.'A' .and. decoded(i+1:i+1).le.'Z' .and. &
+ decoded(i+1:i+1).ne.'F' .and. decoded(i+1:i+1).ne.'G' .and. decoded(i+1:i+1).ne.'I' .and. &
+ decoded(i+2:i+2).eq.'/') go to 2
+
+ if(decoded(i:i).eq.' ' .and. decoded(i+1:i+1).ge.'A' .and. decoded(i+1:i+1).le.'Z' .and. &
+ (decoded(i+2:i+2).eq.'.' .or. decoded(i+2:i+2).eq.'+' .or. decoded(i+2:i+2).eq.'-')) go to 2
+
+ enddo
+
+ if(decoded(1:1).eq.'-' .and. decoded(2:2).le.'1' .and. decoded(2:2).ge.'9') go to 2
+
+ if(decoded(1:1).ge.'1' .and. decoded(1:1).le.'9' .and. &
+ decoded(2:2).ge.'0' .and. decoded(2:2).le.'9' .and. &
+ decoded(3:3).ge.'0' .and. decoded(3:3).le.'9' .and. &
+ decoded(4:4).ne.'W') go to 2
+
+ if(decoded(1:1).ge.'1' .and. decoded(1:1).le.'9' .and. &
+ decoded(2:2).ge.'0' .and. decoded(2:2).le.'9' .and. &
+ decoded(3:3).ne.'W') go to 2
+
+ if(decoded(1:1).ge.'1' .and. decoded(1:1).le.'9' .and. &
+ decoded(2:3).ne.'EL') go to 2
+
+ if(decoded(10:10).ne.'/' .and. decoded(11:11).ne.'/' .and. decoded(12:12).ge.'A' .and. &
+ decoded(12:12).le.'Z' .and. decoded(13:13).ge.'0' .and. decoded(12:12).le.'9') go to 2
+
+ call datacor(datapwr,datacorr)
+
+! ban free message if datacorr is less than 1.55
+ if(datacorr.lt.1.55) go to 2
+
+ ncount=0
+ nchar=0
+
+ do i=1,13
+ if(decoded(i:i).eq.' ') exit
+ if(decoded(i:i).eq.'/' .or. decoded(i:i).eq.'-' .or. decoded(i:i).eq.'.') nchar=nchar+1
+ ncount=ncount+1
+ enddo
+
+ if(ncount.eq.13 .and. nchar.ge.0) go to 2
+
+!print *,"passed"
+!print *,decoded
+
+ go to 4
+
+2 falsedec=.true.
+!print *,"stopped"
+!print *,decoded
+ return
+
+4 return
+end subroutine filtersfreevar
diff --git a/lib/ft8var/four2avar.f90 b/lib/ft8var/four2avar.f90 new file mode 100755 index 00000000..c7df6e99 --- /dev/null +++ b/lib/ft8var/four2avar.f90 @@ -0,0 +1,115 @@ +subroutine four2avar(a,nfft,ndim,isign,iform)
+
+! IFORM = 1, 0 or -1, as data is
+! complex, real, or the first half of a complex array. Transform
+! values are returned in array DATA. They are complex, real, or
+! the first half of a complex array, as IFORM = 1, -1 or 0.
+
+! The transform of a real array (IFORM = 0) dimensioned N(1) by N(2)
+! by ... will be returned in the same array, now considered to
+! be complex of dimensions N(1)/2+1 by N(2) by .... Note that if
+! IFORM = 0 or -1, N(1) must be even, and enough room must be
+! reserved. The missing values may be obtained by complex conjugation.
+
+! The reverse transformation of a half complex array dimensioned
+! N(1)/2+1 by N(2) by ..., is accomplished by setting IFORM
+! to -1. In the N array, N(1) must be the true N(1), not N(1)/2+1.
+! The transform will be real and returned to the input array.
+
+! This version of four2avar makes calls to the FFTW library to do the
+! actual computations.
+
+ parameter (NPMAX=2100) !Max numberf of stored plans
+ parameter (NSMALL=16385) !Max size of "small" FFTs
+ complex a(nfft) !Array to be transformed
+ complex aa(NSMALL) !Local copy of "small" a()
+ integer nn(NPMAX),ns(NPMAX),nf(NPMAX) !Params of stored plans
+ integer*8 nl(NPMAX),nloc !More params of plans
+ integer*8 plan(NPMAX) !Pointers to stored plans
+ logical found_plan
+ data nplan/0/ !Number of stored plans
+ common/patience/npatience,nthreads !Patience and threads for FFTW plans
+ include '/lib/fftw3.f90' !FFTW definitions
+ save plan,nplan,nn,ns,nf,nl
+
+ if(nfft.lt.0) go to 999
+
+ nloc=loc(a)
+ found_plan = .false.
+
+ do i=1,nplan
+ if(nfft.eq.nn(i) .and. isign.eq.ns(i) .and. &
+ iform.eq.nf(i) .and. nloc.eq.nl(i)) then
+ found_plan = .true.
+ exit
+ end if
+ enddo
+
+ if(i.ge.NPMAX) stop 'Too many FFTW plans requested.'
+
+ if (.not. found_plan) then
+ !$omp critical(four2avar_setup)
+ nplan=nplan+1
+ i=nplan
+
+ nn(i)=nfft
+ ns(i)=isign
+ nf(i)=iform
+ nl(i)=nloc
+
+! Planning: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, FFTW_MEASURE,
+! FFTW_PATIENT, FFTW_EXHAUSTIVE
+ nflags=FFTW_ESTIMATE
+ if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT
+ if(npatience.eq.2) nflags=FFTW_MEASURE
+ if(npatience.eq.3) nflags=FFTW_PATIENT
+ if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE
+
+ if(nfft.le.NSMALL) then
+ jz=nfft
+ if(iform.le.0) jz=nfft/2+1
+ aa(1:jz)=a(1:jz)
+ endif
+
+ !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
+ if(isign.eq.-1 .and. iform.eq.1) then
+ call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_FORWARD,nflags)
+ else if(isign.eq.1 .and. iform.eq.1) then
+ call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_BACKWARD,nflags)
+ else if(isign.eq.-1 .and. iform.eq.0) then
+ call sfftw_plan_dft_r2c_1d(plan(i),nfft,a,a,nflags)
+ else if(isign.eq.1 .and. iform.eq.-1) then
+ call sfftw_plan_dft_c2r_1d(plan(i),nfft,a,a,nflags)
+ else
+ stop 'Unsupported request in four2avar'
+ endif
+ !$omp end critical(fftw)
+
+ if(nfft.le.NSMALL) then
+ jz=nfft
+ if(iform.le.0) jz=nfft/2+1
+ a(1:jz)=aa(1:jz)
+ endif
+ !$omp end critical(four2avar_setup)
+ end if
+
+ call sfftw_execute(plan(i))
+ return
+
+999 continue
+
+ !$omp critical(four2avar)
+ do i=1,nplan
+! The test is only to silence a compiler warning:
+ if(ndim.ne.-999) then
+ !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
+ call sfftw_destroy_plan(plan(i))
+ !$omp end critical(fftw)
+ end if
+ enddo
+
+ nplan=0
+ !$omp end critical(four2avar)
+
+ return
+end subroutine four2avar
diff --git a/lib/ft8var/ft4_mod1.f90 b/lib/ft8var/ft4_mod1.f90 new file mode 100755 index 00000000..d1e7349b --- /dev/null +++ b/lib/ft8var/ft4_mod1.f90 @@ -0,0 +1,7 @@ +module ft4_mod1
+
+ real*4 dd4(73728)
+ logical(1) llagcc,lfilter,lhidetest,lhidetelemetry
+ integer nFT4decd,nfafilt,nfbfilt
+
+end module ft4_mod1
\ No newline at end of file diff --git a/lib/ft8var/ft8_decodevar.f90 b/lib/ft8var/ft8_decodevar.f90 new file mode 100755 index 00000000..cde39f39 --- /dev/null +++ b/lib/ft8var/ft8_decodevar.f90 @@ -0,0 +1,481 @@ +module ft8_decodevar
+
+ logical ltry_a8
+ type :: ft8_decodervar
+ procedure(ft8_decodevar_callback), pointer :: callback
+ contains
+ procedure :: decodevar
+ end type ft8_decodervar
+
+ abstract interface
+ subroutine ft8_decodevar_callback (this,snr,dt,freq,decodedvar,nap,qual)
+ import ft8_decodervar
+ implicit none
+ class(ft8_decodervar), intent(inout) :: this
+ integer, intent(in) :: snr
+ integer, intent(in) :: nap
+ real, intent(in) :: dt,freq,qual
+ character(len=37), intent(in) :: decodedvar !ft8md was 26
+ end subroutine ft8_decodevar_callback
+ end interface
+
+contains
+
+ subroutine decodevar(this,callback,nQSOProgress,nfqso,nft8rxfsens,nftx,nutc, &
+ nfa,nfb,ncandthin,ndtcenter,nsec,napwid,lmycallstd,lhiscallstd, &
+ stophint,nthr,numthreads,nagainfil,lft8lowth,lft8subpass,lhideft8dupes)
+
+ use omp_lib
+
+ use ft8_mod1, only : ndecodes,allmessages,allsnrs,allfreq,odd,even,nmsg, &
+ lastrxmsg,lasthcall,calldteven,calldtodd,incall,oddcopy,evencopy, &
+ avexdt,mycall,hiscall,dd8,nft8cycles,ncandallthr,nincallthr,evencq, &
+ oddcq,numcqsig,numdeccq,evenmyc,oddmyc,nummycsig,numdecmyc,lapmyc, &
+ evenqso,oddqso,lqsomsgdcd,hisgrid4
+
+ include 'ft8_params.f90'
+
+ class(ft8_decodervar), intent(inout) :: this
+ procedure(ft8_decodevar_callback) :: callback
+ real, DIMENSION(:), ALLOCATABLE :: dd8m
+ real candidate(4,460),freqsub(200)
+ real qual !ft8md
+ integer, intent(in) :: nQSOProgress,nfqso,nft8rxfsens,nftx,nfa,nfb, &
+ ncandthin,ndtcenter,nsec,napwid,nthr,numthreads
+ logical, intent(in) :: nagainfil
+ logical(1), intent(in) :: stophint,lft8lowth,lft8subpass,lhideft8dupes, &
+ lmycallstd,lhiscallstd
+ logical newdat1,lsubtract,ldupe,lFreeText,lspecial
+ logical(1) lft8sdec,lft8s,lft8sd,lrepliedother,lhashmsg,lqsothread, &
+ lhidemsg,lhighsens,lcqcand,lsubtracted,levenint,loddint,lnohiscall, &
+ lnomycall,lnohisgrid
+ character msg37*37,msg37_2*37,msg26*37,call2*12 !ft8md msg26 was *26
+ character*37 msgsrcvd(130)
+
+ type oddtmp_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type oddtmp_struct
+ type(oddtmp_struct) oddtmp(130)
+
+ type eventmp_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type eventmp_struct
+ type(eventmp_struct) eventmp(130)
+
+ type tmpcqdec_struct
+ real freq
+ real xdt
+ end type tmpcqdec_struct
+ type(tmpcqdec_struct) tmpcqdec(numdeccq) ! 40 sigs
+
+ type tmpcqsig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpcqsig_struct
+ type(tmpcqsig_struct) tmpcqsig(numcqsig) ! 20 sigs
+
+ type tmpmyc_struct
+ real freq
+ real xdt
+ end type tmpmyc_struct
+ type(tmpmyc_struct) tmpmyc(numdecmyc) ! 25 sigs
+
+ type tmpmycsig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpmycsig_struct
+ type(tmpmycsig_struct) tmpmycsig(nummycsig) ! 5 sigs
+
+ type tmpqsosig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpqsosig_struct
+ type(tmpqsosig_struct) tmpqsosig(1)
+
+ this%callback => callback
+
+ oddtmp%lstate=.false.
+ eventmp%lstate=.false.
+ nmsgloc=0
+ ncandthr=0
+ nmsgcq=0
+ tmpcqdec(:)%freq=6000.0
+ nmsgmyc=0
+ tmpmyc(:)%freq=6000.0
+ tmpcqsig(:)%freq=6000.0
+ tmpmycsig(:)%freq=6000.0
+ tmpqsosig(1)%freq=6000.0
+ if(hiscall.eq.'') then
+ lastrxmsg(1)%lstate=.false.
+ else if(lastrxmsg(1)%lstate .and. lasthcall.ne.hiscall .and. &
+ index(lastrxmsg(1)%lastmsg,trim(hiscall)).le.0) then
+ lastrxmsg(1)%lstate=.false.
+ endif
+
+ levenint=.false.
+ loddint=.false.
+ if(nsec.eq.0 .or. nsec.eq.30) then
+ levenint=.true.
+ elseif(nsec.eq.15 .or. nsec.eq.45) then
+ loddint=.true.
+ endif
+
+ lrepliedother=.false.
+ lft8sdec=.false.
+ lqsothread=.false.
+ lsubtracted=.false.
+ ncount=0
+ mycalllen1=len_trim(mycall)+1
+ nincallthr(nthr)=0
+ nallocthr=0
+ ncqsignal=0
+ nmycsignal=0
+
+ lnohiscall=.false.
+ if(len_trim(hiscall).lt.3) lnohiscall=.true.
+ lnomycall=.false.
+ if(len_trim(mycall).lt.3) lnomycall=.true.
+ lnohisgrid=.false.
+ if(len_trim(hisgrid4).ne.4) lnohisgrid=.true.
+ if(nfqso.ge.nfa .and. nfqso.le.nfb) lqsothread=.true.
+
+ if(lqsothread .and. .not.lastrxmsg(1)%lstate .and. .not.stophint .and. &
+ hiscall.ne.'') then
+! got incoming call
+ do i=1,30
+ if(incall(i)%msg(1:1).eq." ") exit
+ if(index(incall(i)%msg,(trim(mycall)//' '//trim(hiscall))).eq.1) then
+ lastrxmsg(1)%lastmsg=incall(i)%msg
+ lastrxmsg(1)%xdt=incall(i)%xdt
+ lastrxmsg(1)%lstate=.true.
+ exit
+ endif
+ enddo
+
+ if(.not.lastrxmsg(1)%lstate) then
+! calling someone, lastrxmsg still not valid
+ if(levenint) then
+ do i=1,130
+ if(.not.evencopy(i)%lstate) cycle
+ if(index(evencopy(i)%msg,' '//trim(hiscall)//' ').gt.1) then
+ lastrxmsg(1)%lastmsg=evencopy(i)%msg
+ lastrxmsg(1)%xdt=evencopy(i)%dt
+ lastrxmsg(1)%lstate=.true.
+ exit
+ endif
+ enddo
+
+ elseif(loddint) then
+ do i=1,130
+ if(.not.oddcopy(i)%lstate) cycle
+ if(index(oddcopy(i)%msg,' '//trim(hiscall)//' ').gt.1) then
+ lastrxmsg(1)%lastmsg=oddcopy(i)%msg
+ lastrxmsg(1)%xdt=oddcopy(i)%dt
+ lastrxmsg(1)%lstate=.true.
+ exit
+ endif
+ enddo
+ endif
+ endif
+ endif
+
+! sliding search over +/- 2.5s relative to 0.5s TX start time
+ jzb=-62 + avexdt*25.
+ jzt=62 + avexdt*25.
+
+ npass=3 ! fallback
+ if(nft8cycles.eq.1) then
+ npass=3
+ else if(nft8cycles.eq.2) then
+ npass=6
+ else if(nft8cycles.eq.3) then
+ npass=9
+ else
+ npass=3
+ endif
+
+ syncmin=1.3
+ do ipass=1,npass
+ newdat1=.true.
+ lsubtract=.true.
+ npos=0
+ if(ipass.eq.1 .or. ipass.eq.4 .or. ipass.eq.7) then
+ if(lft8lowth) syncmin=1.225
+ elseif(ipass.eq.2 .or. ipass.eq.5 .or. ipass.eq.8) then
+ if(lft8lowth) syncmin=1.3
+ elseif(ipass.eq.3 .or. ipass.eq.6 .or. ipass.eq.9) then
+ if(lft8lowth) syncmin=1.1
+ endif
+ if(ipass.gt.5 .or. (ipass.eq.3 .and. npass.eq.3)) lsubtract=.false.
+
+ if(ipass.eq.4) then
+!$omp barrier
+!$omp single
+ if(npass.eq.9) then ! 3 decoding cycles
+ nallocthr=nthr
+ allocate(dd8m(180000), STAT = nAllocateStatus1)
+ if(nAllocateStatus1.ne.0) STOP "Not enough memory"
+ dd8m=dd8
+ endif
+ do i=1,179999
+ dd8(i)=(dd8(i)+dd8(i+1))/2
+ enddo
+!$omp end single
+!$omp barrier
+ else if(ipass.eq.7) then
+!$omp barrier
+ if(nthr.eq.nallocthr) then
+ dd8(1)=dd8m(1)
+ do i=2,180000
+ dd8(i)=(dd8m(i-1)+dd8m(i))/2
+ enddo
+ deallocate (dd8m, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ endif
+!$omp barrier
+ endif
+
+ call sync8var(nfa,nfb,syncmin,nfqso,candidate,ncand,jzb,jzt,ipass, &
+ lqsothread,ncandthin,ndtcenter)
+ do icand=1,ncand
+ sync=candidate(3,icand)
+ f1=candidate(1,icand)
+ xdt=candidate(2,icand)
+ lcqcand=.false.
+ if(candidate(4,icand).gt.1.0) lcqcand=.true.
+ lhighsens=.false.
+ if(sync.lt.1.9 .or. ((ipass.eq.2 .or. ipass.eq.4 .or. ipass.eq.6) &
+ .and. sync.lt.3.15)) lhighsens=.true.
+ lspecial=.false.
+ lFreeText=.false.
+ i3bit=0
+ lft8s=.false.
+ lft8sd=.false.
+ lhashmsg=.false.
+ iaptype=0
+ msg37=''
+ i3=16
+ n3=16
+
+ call ft8bvar(newdat1,nQSOProgress,nfqso,nftx,napwid,lsubtract,npos, &
+ freqsub,tmpcqdec,tmpmyc,nagainfil,iaptype,f1,xdt,nbadcrc, &
+ lft8sdec,msg37,msg37_2,xsnr,stophint,nthr,lFreeText,ipass, &
+ lft8subpass,lspecial,lcqcand,ncqsignal,nmycsignal,npass,i3bit, &
+ lft8s,lmycallstd,lhiscallstd,levenint,loddint,lft8sd,i3,n3, &
+ nft8rxfsens,ncount,msgsrcvd,lrepliedother,lhashmsg,lqsothread, &
+ lft8lowth,lhighsens,lsubtracted,tmpcqsig,tmpmycsig,tmpqsosig, &
+ lnohiscall,lnomycall,lnohisgrid,qual,iaptype2)
+ nsnr=nint(xsnr)
+ xdt=xdt-0.5
+ if(nbadcrc.eq.0) then
+ lhidemsg=.false.
+ if(lspecial) then
+ nspecial=2
+ else
+ nspecial=1
+ endif
+
+!$omp critical(find_dupes)
+ do k=1,nspecial
+ !ft8md if(k.eq.2) msg37=msg37_2 ! this splits DXpedition mode msg into 2 lines
+ ldupe=.false.
+ if(msg37(1:6).eq." ") ldupe=.true.
+ if(.not.ldupe .and. ndecodes.gt.0) then
+ do idec=1,ndecodes
+ if(lhideft8dupes) then
+ if(msg37.eq.allmessages(idec) .and. &
+ (nsnr.le.allsnrs(idec) .or. &
+ (nsnr.gt.allsnrs(idec) .and. &
+ abs(allfreq(idec)-f1).lt.45.0))) then
+ ldupe=.true.
+ exit
+ endif
+ else
+ if(msg37.eq.allmessages(idec) .and. &
+ ((nsnr.le.allsnrs(idec) .and. &
+ abs(allfreq(idec)-f1).lt.45.0) .or. &
+ (nsnr.gt.allsnrs(idec) .and. &
+ abs(allfreq(idec)-f1).lt.45.0 .and. &
+ numthreads.ne.1))) then
+ ldupe=.true.
+ exit
+ endif
+ endif
+ enddo
+ endif
+
+ if(.not.ldupe) then
+ if(.not.lFreeText .and. k.eq.1) call extract_callvar(msg37,call2)
+!!!$omp critical(update_arrays)
+ ndecodes=ndecodes+1
+ allmessages(ndecodes)=msg37
+ allsnrs(ndecodes)=nsnr
+ allfreq(ndecodes)=f1
+
+ if(.not.lhidemsg) then
+ ! simulated wav tests affected, structure contains data for at least previous and current even|odd intervals
+ if(levenint) then
+ calldteven(150:2:-1)=calldteven(150-1:1:-1)
+ calldteven(1)%call2=call2
+ calldteven(1)%dt=xdt
+ else if(loddint) then
+ calldtodd(150:2:-1)=calldtodd(150-1:1:-1)
+ calldtodd(1)%call2=call2
+ calldtodd(1)%dt=xdt
+ endif
+ endif
+!!!$omp end critical(update_arrays)
+
+ if(.not.lhidemsg) then
+ msg26=msg37(1:37) !ft8md was 1:26
+ if(associated(this%callback)) then
+ call this%callback(nsnr,xdt,f1,msg26,iaptype2,qual)
+ endif
+ endif
+
+ if(msg37(1:3).eq.'CQ ' .and. nmsgcq.lt.numdeccq) then
+ nmsgcq=nmsgcq+1
+ xdtr=xdt+0.5
+ tmpcqdec(nmsgcq)%freq=f1
+ tmpcqdec(nmsgcq)%xdt=xdtr
+ endif
+
+ if(lapmyc .and. lmycallstd) then
+ ispc1=index(msg37,' ')
+ if(msg37(1:ispc1-1).eq.trim(mycall) .and. &
+ nmsgmyc.lt.numdecmyc) then
+ nmsgmyc=nmsgmyc+1
+ xdtr=xdt+0.5
+ tmpmyc(nmsgmyc)%freq=f1
+ tmpmyc(nmsgmyc)%xdt=xdtr
+ endif
+ endif
+
+ if(i3.eq.4 .and. msg37(1:3).eq.'CQ ' .and. &
+ mod(nsec,15).eq.0 .and. nmsgloc.lt.130) then
+ nmsgloc=nmsgloc+1
+
+ if(levenint) then
+ eventmp(nmsgloc)%msg=msg37
+ eventmp(nmsgloc)%freq=f1
+ eventmp(nmsgloc)%dt=xdt
+ eventmp(nmsgloc)%lstate=.true.
+ endif
+
+ if(loddint) then
+ oddtmp(nmsgloc)%msg=msg37
+ oddtmp(nmsgloc)%freq=f1
+ oddtmp(nmsgloc)%dt=xdt
+ oddtmp(nmsgloc)%lstate=.true.
+ endif
+ go to 4 ! tmp filled in
+ endif
+
+ if(.not.lFreeText) then
+! protection against any possible free txtmsg bit corruption
+ ispc1=index(msg37,' ')
+ if(.not.lhashmsg .and. mod(nsec,15).eq.0 .and. &
+ ((i3.eq.1 .and. .not.lft8sd) .or. lft8sd) .and. &
+ msg37(1:ispc1-1).ne.trim(mycall) .and. &
+ nmsgloc.lt.130 .and. index(msg37,'<').le.0) then
+
+
+ ! compound callsigns not supported
+ if(index(msg37,'/').gt.0 .and. msg37(1:3).ne.'CQ ') go to 4
+
+ nmsgloc=nmsgloc+1
+ if(levenint) then
+ eventmp(nmsgloc)%msg=msg37
+ eventmp(nmsgloc)%freq=f1
+ eventmp(nmsgloc)%dt=xdt
+ eventmp(nmsgloc)%lstate=.true.
+ endif
+ if(loddint) then
+ oddtmp(nmsgloc)%msg=msg37
+ oddtmp(nmsgloc)%freq=f1
+ oddtmp(nmsgloc)%dt=xdt
+ oddtmp(nmsgloc)%lstate=.true.
+ endif
+ endif
+ endif
+ endif
+4 continue
+ enddo !do k
+!$omp end critical(find_dupes)
+
+ endif
+ enddo !icand
+ ncandthr=ncandthr+ncand
+ enddo !ipass
+
+ if(levenint) then
+ evencq(1:ncqsignal,nthr)%freq=tmpcqsig(1:ncqsignal)%freq
+ evencq(1:ncqsignal,nthr)%xdt=tmpcqsig(1:ncqsignal)%xdt
+ do ik=1,ncqsignal
+ evencq(ik,nthr)%cs=tmpcqsig(ik)%cs
+ enddo
+ if(lapmyc) then
+ evenmyc(1:nmycsignal,nthr)%freq=tmpmycsig(1:nmycsignal)%freq
+ evenmyc(1:nmycsignal,nthr)%xdt=tmpmycsig(1:nmycsignal)%xdt
+ do ik=1,nmycsignal
+ evenmyc(ik,nthr)%cs=tmpmycsig(ik)%cs
+ enddo
+ if(.not.lqsomsgdcd .and. tmpqsosig(1)%freq.lt.5001.) then
+ evenqso(1,nthr)%freq=tmpqsosig(1)%freq
+ evenqso(1,nthr)%xdt=tmpqsosig(1)%xdt
+ evenqso(1,nthr)%cs=tmpqsosig(1)%cs
+ endif
+ endif
+ else if(loddint) then
+ oddcq(1:ncqsignal,nthr)%freq=tmpcqsig(1:ncqsignal)%freq
+ oddcq(1:ncqsignal,nthr)%xdt=tmpcqsig(1:ncqsignal)%xdt
+ do ik=1,ncqsignal
+ oddcq(ik,nthr)%cs=tmpcqsig(ik)%cs
+ enddo
+ if(lapmyc) then
+ oddmyc(1:nmycsignal,nthr)%freq=tmpmycsig(1:nmycsignal)%freq
+ oddmyc(1:nmycsignal,nthr)%xdt=tmpmycsig(1:nmycsignal)%xdt
+ do ik=1,nmycsignal
+ oddmyc(ik,nthr)%cs=tmpmycsig(ik)%cs
+ enddo
+ if(.not.lqsomsgdcd .and. tmpqsosig(1)%freq.lt.5001.) then
+ oddqso(1,nthr)%freq=tmpqsosig(1)%freq
+ oddqso(1,nthr)%xdt=tmpqsosig(1)%xdt
+ oddqso(1,nthr)%cs=tmpqsosig(1)%cs
+ endif
+ endif
+ endif
+
+ ncandthr=nint(float(ncandthr)/npass)
+ ncandallthr(nthr)=ncandallthr(nthr)+ncandthr
+
+ if(nmsgloc.gt.0) then
+!$omp critical(update_structures)
+ if(levenint) then
+ even(nmsg+1:nmsg+nmsgloc)%msg=eventmp(1:nmsgloc)%msg
+ even(nmsg+1:nmsg+nmsgloc)%freq=eventmp(1:nmsgloc)%freq
+ even(nmsg+1:nmsg+nmsgloc)%dt=eventmp(1:nmsgloc)%dt
+ even(nmsg+1:nmsg+nmsgloc)%lstate=eventmp(1:nmsgloc)%lstate
+ nmsg=nmsg+nmsgloc
+ else if(loddint) then
+ odd(nmsg+1:nmsg+nmsgloc)%msg=oddtmp(1:nmsgloc)%msg
+ odd(nmsg+1:nmsg+nmsgloc)%freq=oddtmp(1:nmsgloc)%freq
+ odd(nmsg+1:nmsg+nmsgloc)%dt=oddtmp(1:nmsgloc)%dt
+ odd(nmsg+1:nmsg+nmsgloc)%lstate=oddtmp(1:nmsgloc)%lstate
+ nmsg=nmsg+nmsgloc
+ endif
+!$omp end critical(update_structures)
+ endif
+
+ return
+ end subroutine decodevar
+end module ft8_decodevar
diff --git a/lib/ft8var/ft8_downsamplevar.f90 b/lib/ft8var/ft8_downsamplevar.f90 new file mode 100755 index 00000000..7ef178b6 --- /dev/null +++ b/lib/ft8var/ft8_downsamplevar.f90 @@ -0,0 +1,63 @@ +subroutine ft8_downsamplevar(newdat1,f0,nqso,c0,c2,c3,lhighsens,lsubtracted,npos,freqsub)
+
+! Downconvert to complex data sampled at 200 Hz ==> 32 samples/symbol
+ use ft8_mod1, only : dd8,windowc1,facc1
+ parameter (NFFT1=192000,NFFT2=3200) !192000/60 = 3200
+
+ logical newdat1
+ complex, intent(out) :: c0(-800:4000),c2(-800:4000),c3(-800:4000)
+ complex cx(0:96000),cxx(0:96000),c1(0:3199) ! 0:NFFT1/2
+ real x(NFFT1)
+ real, intent(in) :: f0
+ integer, intent(in) :: nqso
+ real freqsub(200)
+ logical(1), intent(in) :: lhighsens
+ logical(1) lsubtracted,ldofft
+ equivalence (x,cx)
+ save cxx
+
+ ldofft=.false.
+ if(lsubtracted) then
+ do i=1,npos
+ if(abs(f0-freqsub(i)).lt.50.) then; ldofft=.true.; lsubtracted=.false.; exit; endif
+ enddo
+ endif
+
+ if(newdat1 .or. ldofft) then
+! Data in dd have changed, recompute the long FFT
+ x(1:180000)=dd8
+ x(180001:NFFT1)=0. !Zero-pad the x array
+ call four2avar(cx,NFFT1,1,-1,0) !r2c FFT to freq domain
+ newdat1=.false.; ldofft=.false.; npos=0
+ cxx=cx
+ endif
+
+ df=0.0625 ! 12000.0/NFFT1
+! tonewidth=6.25 Hz ! 12000.0/1920.
+ i0=nint(f0/df)
+ ft=f0+55.75; it=min(nint(ft/df),96000)
+ fb=f0-5.75; ib=max(1,nint(fb/df))
+ c1=cmplx(0.0,0.0)
+ k=it-ib
+ c1(0:k)=cxx(ib:it)
+ c1(0:54)=c1(0:54)*windowc1(54:0:-1)
+ c1(k-54:k)=c1(k-54:k)*windowc1
+ c1=cshift(c1,i0-ib)
+ if(lhighsens) then; c1(0)=c1(0)*1.93; c1(799)=c1(799)*1.7; c1(800)=c1(800)*1.7; c1(3199)=c1(3199)*1.93
+ else; c1(45)=c1(45)*1.49; c1(54)=c1(54)*1.49; c1(3145)=c1(3145)*1.49; c1(3154)=c1(3154)*1.49
+ endif ! 10346..10347
+ call four2avar(c1,NFFT2,1,1,1) !c2c FFT back to time domain
+ c0(-800:-1)=0.; c0(0:3199)=facc1*c1(0:3199); c0(3200:4000)=0.
+ if(nqso.gt.1) then
+ c2(-800:-1)=0.; c2(3200:4000)=0.
+ do i=0,3198; c2(i)=c0(i)+c0(i+1); enddo
+ c2(3199)=c0(3199); c2=c2/2
+ endif
+ if(nqso.eq.3) then
+ c3(-800:-1)=0.; c3(3200:4000)=0.
+ do i=1,3199; c3(i)=c0(i-1)+c0(i); enddo
+ c3(0)=c0(0); c3=c3/2
+ endif
+
+ return
+end subroutine ft8_downsamplevar
diff --git a/lib/ft8var/ft8_mod1.f90 b/lib/ft8var/ft8_mod1.f90 new file mode 100755 index 00000000..aba90550 --- /dev/null +++ b/lib/ft8var/ft8_mod1.f90 @@ -0,0 +1,203 @@ +module ft8_mod1
+
+ parameter (NPS=180000,NFR=151680,NFILT1=4000,NFILT2=3400,numcqsig=20, &
+ numdeccq=40,nummycsig=5,numdecmyc=25,nmaxthreads=24)
+ real*4 dd8(nps)
+ real endcorr(NFILT1/2+1)
+ complex cw(nps),csync(0:6,32),csynce(0:18,32),csyncsd(0:18,32), &
+ csyncsdcq(0:57,32),csynccq(0:7,32),ctwkw(11,32),ctwkn(11,32), &
+ ctwk256(256)
+ character*37 allmessages(200),msgsd76(76),msg(56),msgroot,msgincall(174)
+ character lasthcall*12,mycall12_0*12,mycall12_00*12,hiscall12_0*12, &
+ hisgrid4*4,hisgrid*6 !ft8md w3sz added hisgrid
+ character(len=12) :: mycall,hiscall,mybcall,hisbcall
+ real allfreq(200),windowc1(0:54),windowx(0:200),pivalue,facx,twopi, &
+ facc1,dt,sumxdtt(24),avexdt,xdtincall(174)
+ integer itone76(76,79),idtone76(76,58),itone56(56,79),idtone56(56,58), &
+ idtone25(25,58),allsnrs(200),apsym(58),idtonemyc(58),mcq(29), &
+ mrrr(19),m73(19),mrr73(19),naptypes(0:5,27),icos7(0:6), &
+ graymap(0:7),nappasses(0:5),nmsg,ndecodes,nlasttx,mycalllen1, &
+ msgrootlen,nfawide,nfbwide,nhaptypes(0:5,27),apsymsp(66), &
+ apsymdxns1(58),apsymdxnsrrr(77),ndxnsaptypes(0:5,27),apcqsym(77), &
+ apsymdxnsrr73(77),apsymdxns73(77),nft8cycles,ncandallthr(24), &
+ maskincallthr(25),nincallthr(24),idtonecqdxcns(58),apsymmyns1(29), &
+ apsymmyns2(58),apsymmynsrr73(77),apsymmyns73(77), &
+ nmycnsaptypes(0:5,27),apsymdxstd(58),apsymdxnsr73(77), &
+ apsymdxns732(77),apsymmynsrrr(77),idtonedxcns73(58), &
+ idtonefox73(58),idtonespec(58),nintcount
+ integer*1 gen(91,174)
+ logical one(0:511,0:8),lqsomsgdcd,first_osd
+ logical(1) lapmyc,lagcc,lagccbail,lhound,lenabledxcsearch, &
+ lwidedxcsearch,lmultinst,lskiptx1,ltxing
+ data maskincallthr/0,30,45,55,65,75,85,90,95,100,105,110,115,120,125, &
+ 130,135,140,145,150,155,160,165,170,175/
+ 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 icos7/3,1,4,0,6,5,2/
+ data graymap/0,1,3,2,5,6,4,7/
+ data mycall12_0/'dummy'/
+ data mycall12_00/'dummy'/
+ data hiscall12_0/'dummy'/
+
+! Hound OFF, MyCall is standard, DXCall is standard or empty
+ data naptypes(0,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx6 CQ
+ data naptypes(1,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx1 Grid
+ data naptypes(2,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx2 Report
+ data naptypes(3,1:27)/3,3,3,6,6,6,5,5,5,4,4,4,0,0,0,0,0,0,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx3 RRreport
+ data naptypes(4,1:27)/3,3,3,6,6,6,5,5,5,4,4,4,2,2,2,0,0,0,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx4 RRR,RR73
+ data naptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36, &
+ 36,36,35,35,35/ ! Tx5 73
+
+! Hound OFF, MyCall is non-standard, DXCall is standard or empty
+ data nmycnsaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,40,40,40,1,1,1,31, &
+ 31,31,36,36,36,35,35,35/ ! Tx6 CQ
+ data nmycnsaptypes(1,1:27)/41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31, &
+ 31,31,36,36,36,35,35,35/ ! Tx1 DXcall MyCall
+ data nmycnsaptypes(2,1:27)/41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31, &
+ 31,31,36,36,36,35,35,35/ ! Tx2 Report
+ data nmycnsaptypes(3,1:27)/41,41,41,44,44,44,43,43,43,42,42,42,0,0,0,0, &
+ 0,0,31,31,31,36,36,36,35,35,35/ ! Tx3 RRreport
+ data nmycnsaptypes(4,1:27)/41,41,41,44,44,44,43,43,43,42,42,42,40,40,40,&
+ 0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx4 RRR,RR73
+ data nmycnsaptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,40,40,40,1,1,1,31,31,&
+ 31,36,36,36,35,35,35/ ! Tx5 73
+
+! Hound mode
+ data nhaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0, &
+ 111,111,111/ ! Tx6 CQ, possible in idle mode if DXCall is empty
+ data nhaptypes(1,1:27)/21,21,21,22,22,22,0,0,0,0,0,0,0,0,0,31,31,31,0,0,&
+ 0,36,36,36,0,0,0/ ! Tx1 Grid idle mode or transmitting
+ data nhaptypes(2,1:27)/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,0/ ! Tx2 none
+ data nhaptypes(3,1:27)/21,21,21,22,22,22,23,23,23,24,24,24,0,0,0,0,0,0, &
+ 0,0,0,0,0,0,0,0,0/ ! Tx3 RRreport QSO in progress or QSO is finished
+ data nhaptypes(4,1:27)/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,0/ ! Tx4 none
+ data nhaptypes(5,1:27)/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,0/ ! Tx5 none
+
+!Non-standard DXCall
+ data ndxnsaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31, &
+ 36,36,36,35,35,35/ ! Tx6 CQ
+ data ndxnsaptypes(1,1:27)/11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31, &
+ 31,36,36,36,35,35,35/ ! Tx1 Grid
+ data ndxnsaptypes(2,1:27)/11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31, &
+ 31,36,36,36,35,35,35/ ! Tx2 Report
+ data ndxnsaptypes(3,1:27)/11,11,11,14,14,14,13,13,13,12,12,12,0,0,0,0, &
+ 0,0,31,31,31,36,36,36,35,35,35/ ! Tx3 RRreport
+ data ndxnsaptypes(4,1:27)/11,11,11,14,14,14,13,13,13,12,12,12,2,2,2,0, &
+ 0,0,31,31,31,36,36,36,35,35,35/ ! Tx4 RRR,RR73
+ data ndxnsaptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31, &
+ 36,36,36,35,35,35/ ! Tx5 73
+ data nintcount/0/
+ data avexdt/0.0/
+ data first_osd/.true./
+
+ type odd_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type odd_struct
+ type(odd_struct) odd(130)
+
+ type even_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type even_struct
+ type(even_struct) even(130)
+
+ type oddcopy_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type oddcopy_struct
+ type(oddcopy_struct) oddcopy(130)
+
+ type evencopy_struct
+ real freq
+ real dt
+ logical lstate
+ character*37 msg
+ end type evencopy_struct
+ type(evencopy_struct) evencopy(130)
+
+ type lastrxmsg_struct
+ real xdt
+ logical lstate
+ character*37 lastmsg
+ end type lastrxmsg_struct
+ type (lastrxmsg_struct) lastrxmsg(1)
+ data lastrxmsg%lstate/.false./
+
+ type callsigndtodd_struct
+ real dt
+ character*12 call2
+ end type callsigndtodd_struct
+ type (callsigndtodd_struct) calldtodd(150)
+
+ type callsigndteven_struct
+ real dt
+ character*12 call2
+ end type callsigndteven_struct
+ type (callsigndteven_struct) calldteven(150)
+
+ type incall_struct
+ real xdt
+ character*37 msg
+ end type incall_struct
+ type (incall_struct) incall(30)
+
+ type evencq_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type evencq_struct
+ type(evencq_struct) evencq(numcqsig,nmaxthreads) ! 24 threads
+
+ type oddcq_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type oddcq_struct
+ type(oddcq_struct) oddcq(numcqsig,nmaxthreads)
+
+ type evenmyc_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type evenmyc_struct
+ type(evenmyc_struct) evenmyc(nummycsig,nmaxthreads)
+
+ type oddmyc_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type oddmyc_struct
+ type(oddmyc_struct) oddmyc(nummycsig,nmaxthreads)
+
+ type evenqso_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type evenqso_struct
+ type(evenqso_struct) evenqso(1,nmaxthreads)
+
+ type oddqso_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type oddqso_struct
+ type(oddqso_struct) oddqso(1,nmaxthreads)
+
+end module ft8_mod1
diff --git a/lib/ft8var/ft8_params.f90 b/lib/ft8var/ft8_params.f90 new file mode 100755 index 00000000..d8e57840 --- /dev/null +++ b/lib/ft8var/ft8_params.f90 @@ -0,0 +1,12 @@ +! LDPC (174,91) code
+parameter (KK=91) !Information bits (77 + CRC14)
+parameter (ND=58) !Data symbols
+parameter (NS=21) !Sync symbols (3 @ Costas 7x7)
+parameter (NN=79) !Total channel symbols NS+ND (79)
+parameter (NSPS=1920) !Samples per symbol at 12000 S/s
+parameter (NZ=151680) !Samples in full 15 s waveform NSPS*NN (151,680)
+parameter (NMAX=180000) !Samples in iwave 15s*12000 (180,000)
+parameter (NFFT1=3840, NH1=1920) !Length of FFTs for symbol spectra NFFT1=2*NSPS, NH1=NFFT1/2
+parameter (NSTEP=480) !Rough time-sync step size NSTEP=NSPS/4
+parameter (NHSYM=372) !Number of symbol spectra (1/4-sym steps) NHSYM=NMAX/NSTEP-3
+parameter (NDOWN=60) !Downsample factor
diff --git a/lib/ft8var/ft8apsetvar.f90 b/lib/ft8var/ft8apsetvar.f90 new file mode 100755 index 00000000..3999691b --- /dev/null +++ b/lib/ft8var/ft8apsetvar.f90 @@ -0,0 +1,216 @@ +subroutine ft8apsetvar(lmycallstd,lhiscallstd,numthreads)
+
+ use packjt77var
+ use ft8_mod1, only : apsym,mycall,hiscall,apsymsp,lhound,apsymdxns1,apsymdxnsrrr,mybcall,hisbcall,apcqsym,hisgrid4, &
+ apsymdxnsrr73,apsymdxns73,apsymmyns1,apsymmyns2,apsymmynsrr73,apsymmyns73,apsymdxstd,apsymdxnsr73, &
+ apsymdxns732,apsymmynsrrr
+ character*77 c77
+ character*37 msg,msgchk
+ character*12 hiscallt,mycallprev,hiscallprev
+ logical lnohiscall,unpk77_success,first
+ logical(1) lhoundprev
+ logical(1), intent(in) :: lmycallstd,lhiscallstd
+ data mycallprev/'QQ2QQ'/
+ data hiscallprev/'QQ1QQ'/
+ data lhoundprev/.false./
+ data first/.true./
+ save hiscallprev,mycallprev,lhoundprev,first
+
+ if(hiscall.ne.hiscallprev .or. mycall.ne.mycallprev .or. (lhound.neqv.lhoundprev) .or. first) then ! first for lhound triggered
+
+ first=.false.; mycallprev=mycall; lhoundprev=lhound
+
+! shall hash both callsigns for making AP masks with nonstandard callsign message
+ if(.not.lhound) call fillhashvar(numthreads,.true.)
+
+ lnohiscall=.false.
+ hiscallt=hiscall
+ if(len_trim(hiscallt).lt.3) then
+ hiscallt=mycall ! use mycall for dummy hiscall - mycall won't be hashed
+ lnohiscall=.true.
+ endif
+
+ if(hiscall.ne.hiscallprev) then
+ hiscallprev=hiscall
+! Encode a dummy standard message: i3=1, 28 1 28 1 1 15
+ if(len_trim(hiscall).gt.2) then
+ if(lhiscallstd .and. len_trim(hisgrid4).eq.4) then; msg='CQ '//trim(hiscall)//' '//trim(hisgrid4)
+ else; msg='CQ '//trim(hiscall)
+ endif
+
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(lhiscallstd .and. i3.ne.1 .or. .not.lhiscallstd .and. i3.ne.4 .or. (msg.ne.msgchk) .or. .not.unpk77_success) go to 1
+ read(c77,'(77i1)',err=1) apcqsym(1:77)
+ apcqsym=2*apcqsym-1
+ endif
+
+ if(lhiscallstd .and. .not.lmycallstd) then
+ msg=trim(hiscall)//' '//trim(hiscall)//' RRR'
+ i3=0; n3=0
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.1 .or. (msg.ne.msgchk) .or. .not.unpk77_success) go to 2
+ read(c77,'(58i1)',err=2) apsymdxstd(1:58)
+ apsymdxstd=2*apsymdxstd-1
+ endif
+
+ if(.not.lhound .and. .not.lhiscallstd .and. len_trim(hiscall).gt.2) then
+! nonstandard DXCall searching
+ msg='<W9XYZ> '//trim(hiscall)//' RR73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.4 .or. .not.unpk77_success) go to 3
+ read(c77,'(77i1)',err=3) apsymdxnsrr73(1:77)
+ apsymdxnsrr73=2*apsymdxnsrr73-1
+
+ msg='<W9XYZ> '//trim(hiscall)//' 73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.4 .or. .not.unpk77_success) go to 4
+ read(c77,'(77i1)',err=4) apsymdxns73(1:77)
+ apsymdxns73=2*apsymdxns73-1
+ endif
+ endif
+
+ if(.not.lhound .and. .not.lmycallstd .and. len_trim(mycall).gt.2) then
+ if(lhiscallstd) then
+ msg='<'//trim(mycall)//'> '//trim(hiscall)//' -15'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+ if(i3.ne.1 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 5
+ read(c77,'(58i1)',err=5) apsymmyns2(1:58)
+ apsymmyns2=2*apsymmyns2-1
+
+ nlenmyc=len_trim(mycall)
+ msg=trim(mycall)//' <'//trim(hiscall)//'> RR73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 6
+ read(c77,'(77i1)',err=6) apsymmynsrr73(1:77)
+ apsymmynsrr73=2*apsymmynsrr73-1
+ msg=trim(mycall)//' <'//trim(hiscall)//'> 73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 7
+ read(c77,'(77i1)',err=7) apsymmyns73(1:77)
+ apsymmyns73=2*apsymmyns73-1
+ msg=trim(mycall)//' <'//trim(hiscall)//'> RRR'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 15
+ read(c77,'(77i1)',err=15) apsymmynsrrr(1:77)
+ apsymmynsrrr=2*apsymmynsrrr-1
+
+ else if(lnohiscall) then
+
+ msg='<'//trim(mycall)//'> ZZ1ZZZ -15'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+ if(i3.ne.1 .or. msgchk.ne.msg .or. .not.unpk77_success) go to 8
+ read(c77,'(29i1)',err=8) apsymmyns1(1:29)
+ apsymmyns1=2*apsymmyns1-1
+ endif
+ endif
+
+ if(len_trim(mycall).lt.3) return
+
+ if(.not.lhound .and. lmycallstd .and. (lhiscallstd .or. lnohiscall)) then
+ msg=trim(mycall)//' '//trim(hiscallt)//' RRR'
+ i3=0; n3=0
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.1 .or. (msg.ne.msgchk) .or. .not.unpk77_success) go to 9
+ read(c77,'(58i1)',err=9) apsym(1:58)
+ apsym=2*apsym-1; if(lnohiscall) apsym(30)=99
+ endif
+
+ if(lhound) then
+! standard messages from Fox, always base callsigns
+ if(len_trim(hisbcall).gt.2 .and. len_trim(mybcall).gt.2) then
+ msg=trim(mybcall)//' '//trim(hisbcall)//' -15'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.1 .or. (msg.ne.msgchk) .or. .not.unpk77_success) go to 9
+ read(c77,'(58i1)',err=9) apsym(1:58)
+ apsym=2*apsym-1
+ else
+ apsym(30)=99
+ endif
+
+! special messages
+ msg=trim(mycall)//' RR73; '//trim(mycall)//' <'//trim(hiscallt)//'> -16'
+ i3=0; n3=1
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ i1=0; i1=index(msgchk,'<'); if(i1.lt.15) return
+ if(i3.ne.0 .or. msg(1:i1).ne.msgchk(1:i1) .or. .not.unpk77_success) go to 10
+ read(c77,'(66i1)',err=10) apsymsp(1:66)
+ apsymsp=2*apsymsp-1!; if(lnohiscall) apsymsp(30)=99
+ endif
+
+ if(.not.lhound .and. lmycallstd .and. .not.lhiscallstd .and. len_trim(hiscall).gt.2) then
+ msg=trim(mycall)//' <'//trim(hiscall)//'> -16' ! report, rreport
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.1 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 11
+ read(c77,'(58i1)',err=11) apsymdxns1(1:58)
+ apsymdxns1=2*apsymdxns1-1
+
+ msg='<'//trim(mycall)//'> '//trim(hiscall)//' RRR'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 12
+ read(c77,'(77i1)',err=12) apsymdxnsrrr(1:77)
+ apsymdxnsrrr=2*apsymdxnsrrr-1
+
+ msg='<'//trim(mycall)//'> '//trim(hiscall)//' RR73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 13
+ read(c77,'(77i1)',err=13) apsymdxnsr73(1:77)
+ apsymdxnsr73=2*apsymdxnsr73-1
+
+ msg='<'//trim(mycall)//'> '//trim(hiscall)//' 73'
+ call pack77var(msg,i3,n3,c77,0)
+ call unpack77var(c77,1,msgchk,unpk77_success,25)
+!read(c77(75:77),'(b3)') k3; print *,'i3 =',k3; print *,msgchk
+ if(i3.ne.4 .or. msg.ne.msgchk .or. .not.unpk77_success) go to 14
+ read(c77,'(77i1)',err=14) apsymdxns732(1:77)
+ apsymdxns732=2*apsymdxns732-1
+ endif
+
+ endif
+
+ go to 32
+
+1 apcqsym=0; apcqsym(1)=99; apcqsym(30)=99; go to 32
+2 apsymdxstd=0; apsymdxstd(1)=99; apsymdxstd(30)=99; go to 32
+3 apsymdxnsrr73=0; apsymdxnsrr73(1)=99; apsymdxnsrr73(30)=99; go to 32
+4 apsymdxns73=0; apsymdxns73(1)=99; apsymdxns73(30)=99; go to 32
+5 apsymmyns2=0; apsymmyns2(1)=99; apsymmyns2(30)=99; go to 32
+6 apsymmynsrr73=0; apsymmynsrr73(1)=99; apsymmynsrr73(30)=99; go to 32
+7 apsymmyns73=0; apsymmyns73(1)=99; apsymmyns73(30)=99; go to 32
+8 apsymmyns1=0; apsymmyns1(1)=99; go to 32
+9 apsym=0; apsym(1)=99; apsym(30)=99; go to 32
+10 apsymsp=0; apsymsp(1)=99; apsymsp(30)=99; go to 32
+11 apsymdxns1=0; apsymdxns1(1)=99; apsymdxns1(30)=99; go to 32
+12 apsymdxnsrrr=0; apsymdxnsrrr(1)=99; apsymdxnsrrr(30)=99; go to 32
+13 apsymdxnsr73=0; apsymdxnsr73(1)=99; apsymdxnsr73(30)=99; go to 32
+14 apsymdxns732=0; apsymdxns732(1)=99; apsymdxns732(30)=99; go to 32
+15 apsymmynsrrr=0; apsymmynsrrr(1)=99; apsymmynsrrr(30)=99; go to 32
+
+32 continue
+
+ return
+end subroutine ft8apsetvar
diff --git a/lib/ft8var/ft8bvar.f90 b/lib/ft8var/ft8bvar.f90 new file mode 100755 index 00000000..54004883 --- /dev/null +++ b/lib/ft8var/ft8bvar.f90 @@ -0,0 +1,2952 @@ +subroutine ft8bvar(newdat1,nQSOProgress,nfqso,nftx,napwid,lsubtract,npos,freqsub, &
+ tmpcqdec,tmpmyc,nagainfil,iaptype,f1,xdt,nbadcrc,lft8sdec,msg37,msg37_2, &
+ xsnr,stophint,nthr,lFreeText,ipass,lft8subpass,lspecial,lcqcand,ncqsignal, &
+ nmycsignal,npass,i3bit,lft8s,lmycallstd,lhiscallstd,levenint,loddint,lft8sd, &
+ i3,n3,nft8rxfsens,ncount,msgsrcvd,lrepliedother,lhashmsg,lqsothread, &
+ lft8lowth,lhighsens,lsubtracted,tmpcqsig,tmpmycsig,tmpqsosig,lnohiscall, &
+ lnomycall,lnohisgrid,qual,iaptype2)
+
+ use packjt77var, only : unpack77var
+ use ft8_mod1, only : allmessages,ndecodes,apsym,mcq,m73,mrr73,mrrr,icos7, &
+ naptypes,nhaptypes,one,graymap,oddcopy,evencopy,lastrxmsg,lasthcall, &
+ nlasttx,calldteven,calldtodd,lqsomsgdcd,mycalllen1,msgroot,msgrootlen, &
+ allfreq,idtone25,lapmyc,idtonemyc,mycall,hiscall,lhound,apsymsp, &
+ ndxnsaptypes,apsymdxns1,apsymdxnsrrr,lenabledxcsearch,lwidedxcsearch, &
+ apcqsym,apsymdxnsrr73,apsymdxns73,mybcall,hisbcall,lskiptx1,nft8cycles, &
+ ctwkw,ctwkn,nincallthr,msgincall,xdtincall,maskincallthr,ctwk256,numcqsig, &
+ numdeccq,evencq,oddcq,nummycsig,numdecmyc,evenmyc,oddmyc,idtone56, &
+ idtonecqdxcns,evenqso,oddqso,nmycnsaptypes,apsymmyns1,apsymmyns2, &
+ apsymmynsrr73,apsymmyns73,apsymdxstd,apsymdxnsr73,apsymdxns732,ltxing, &
+ apsymmynsrrr,idtonedxcns73,idtonefox73,idtonespec !ft8md added
+
+ include 'ft8_params.f90'
+ character c77*77,msg37*37,msg37_2*37,msgd*37,msgbase37*37,call_a*12,call_b*12
+ character callsign*12,grid*12
+ character*37 msgsrcvd(130)
+ complex cd0(-800:4000),cd1(-800:4000),cd2(-800:4000),cd3(-800:4000),ctwk(32), &
+ csymb(32),cs(0:7,79),csymbr(32),csr(0:7,79),csig(32),csig0(151680),z1, &
+ csymb256(256),cstmp2(0:7,79),csold(0:7,79),cscs(0:7,79)
+ real a(5),s8(0:7,79),s82(0:7,79),s2(0:511),sp(0:7),s81(0:7),snrsync(21), &
+ syncw(7),sumkw(7),scoreratiow(7),freqsub(200),s256(0:8),s2563(0:26), &
+ syncavpart(3)
+ real bmeta(174),bmetb(174),bmetc(174),bmetd(174)
+ real llra(174),llrb(174),llrc(174),llrd(174),llrz(174)
+ real qual !ft8md
+ integer*1 message77(77),apmask(174),cw(174),nsmax(8)
+ integer itone(79),ip(1),ka(1),nqsoend(3)
+ integer, intent(in) :: nQSOProgress,nfqso,nftx,napwid,nthr,ipass,nft8rxfsens
+ logical newdat1,lsubtract,lFreeText,nagainfil,lspecial,unpk77_success
+ logical(1), intent(in) :: stophint,lft8subpass,lmycallstd,lhiscallstd, &
+ lqsothread,lft8lowth,lhighsens,lcqcand,levenint,loddint,lnohiscall, &
+ lnomycall,lnohisgrid
+ logical(1) falsedec,lastsync,ldupemsg,lft8s,lft8sdec,lft8sd,lsdone,ldupeft8sd, &
+ lrepliedother,lhashmsg,lvirtual2,lvirtual3,lsd,lcq,ldeepsync,lcallsstd, &
+ lfound,lsubptxfreq,lreverse,lchkcall,lgvalid,lwrongcall,lsubtracted, &
+ lcqsignal,loutapwid,lfoundcq,lmycsignal,lfoundmyc,lqsosig,ldxcsig, &
+ lcqdxcsig,lcqdxcnssig,lqsocandave,lcall1hash,lqsosigtype3,lqso73,lqsorr73, &
+ lqsorrr,lfoxspecrpt,lfoxstdr73,lapcqonly,lcall2hash,lskipnotap
+ integer iaptype2
+
+ type tmpcqdec_struct
+ real freq
+ real xdt
+ end type tmpcqdec_struct
+ type(tmpcqdec_struct) tmpcqdec(numdeccq)
+
+ type tmpcqsig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpcqsig_struct
+ type(tmpcqsig_struct) tmpcqsig(numcqsig) ! 20 sigs 24 threads
+
+ type tmpmyc_struct
+ real freq
+ real xdt
+ end type tmpmyc_struct
+ type(tmpmyc_struct) tmpmyc(numdecmyc)
+
+ type tmpmycsig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpmycsig_struct
+ type(tmpmycsig_struct) tmpmycsig(nummycsig) ! 5 sigs
+
+ type tmpqsosig_struct
+ real freq
+ real xdt
+ complex cs(0:7,79)
+ end type tmpqsosig_struct
+ type(tmpqsosig_struct) tmpqsosig(1)
+
+ iaptype2 = 99 !ft8md
+
+ max_iterations=30
+ nharderrors=-1
+ nbadcrc=1
+ delfbest=0.
+ ibest=0
+ dfqso=500.
+ rrxdt=0.5
+ fs2=200.
+ dt2=0.005 ! fs2=12000.0/NDOWN; dt2=1.0/fs2
+ lcall1hash=.false.
+ lcall2hash=.false.
+ lskipnotap=.false.
+ ldeepsync=.false.
+ if(lft8lowth .or. lft8subpass) ldeepsync=.true.
+ lcallsstd=.true.
+ if(.not.lmycallstd .or. .not.lhiscallstd) lcallsstd=.false.
+
+ xdt0=xdt
+ f10=f1
+! apply last freq f1 and last DT criteria here
+ nqso=1
+ if(lqsothread .and. .not. lft8sdec .and. .not.lqsomsgdcd .and. .not.stophint &
+ .and. nlasttx.ge.1 .and. nlasttx.le.4 .and. abs(f10-nfqso).lt.2.51) then
+ if(lastrxmsg(1)%lstate .and. abs(lastrxmsg(1)%xdt-xdt).lt.0.18) then
+ nqso=2
+ elseif(.not.lastrxmsg(1)%lstate) then
+ nqso=2
+ endif
+ endif
+
+ lvirtual2=.false.
+ lvirtual3=.false.
+ maxlasttx=4
+ if(lqsothread .and. .not. lft8sdec .and. .not.lqsomsgdcd) then
+ if(len_trim(hiscall).gt.2) then
+ if(xdt.gt.4.9 .or. xdt.lt.-4.9) then
+ if(lastrxmsg(1)%lstate .and. trim(lastrxmsg(1)%lastmsg).eq.trim(msgroot)//&
+ ' RRR') maxlasttx=5
+ endif
+ if(xdt.gt.4.9) then
+ if(.not.stophint .and. nlasttx.ge.1 .and. nlasttx.le.maxlasttx .and. &
+ abs(f10-nfqso).lt.0.1) then
+ if(lastrxmsg(1)%lstate) then
+ xdt0=lastrxmsg(1)%xdt
+ nqso=2
+ lvirtual2=.true.
+ endif
+ if(.not.lastrxmsg(1)%lstate) then
+ if(levenint) then
+ do i=1,150
+ if(trim(calldteven(i)%call2).eq.trim(hiscall)) then
+ xdt0=calldteven(i)%dt
+ nqso=3
+ lvirtual2=.true.
+ exit
+ endif
+ enddo
+ else if(loddint) then
+ do i=1,150
+ if(trim(calldtodd(i)%call2).eq.trim(hiscall)) then
+ xdt0=calldtodd(i)%dt
+ nqso=3
+ lvirtual2=.true.
+ exit
+ endif
+ enddo
+ endif
+ endif
+ endif
+ elseif (xdt.lt.-4.9) then
+ if(.not.stophint .and. nlasttx.ge.1 .and. nlasttx.le.maxlasttx .and. &
+ abs(f10-nfqso).lt.0.1) then
+ if(lastrxmsg(1)%lstate) then
+ xdt0=lastrxmsg(1)%xdt
+ nqso=3
+ lvirtual3=.true.
+ endif
+ if(.not.lastrxmsg(1)%lstate) then
+ if(levenint) then
+ do i=1,150
+ if(trim(calldteven(i)%call2).eq.trim(hiscall)) then
+ xdt0=calldteven(i)%dt
+ nqso=3
+ lvirtual3=.true.
+ exit
+ endif
+ enddo
+ else if(loddint) then
+ do i=1,150
+ if(trim(calldtodd(i)%call2).eq.trim(hiscall)) then
+ xdt0=calldtodd(i)%dt
+ nqso=3
+ lvirtual3=.true.
+ exit
+ endif
+ enddo
+ endif
+ endif
+ endif
+ endif
+ endif
+ endif
+
+ call ft8_downsamplevar(newdat1,f1,nqso,cd0,cd2,cd3,lhighsens,lsubtracted,npos, &
+ freqsub) !Mix f1 to baseband and downsample
+
+ lsd=.false.
+ isd=1
+ lcq=.false.
+ if(levenint) then
+ do i=1,130
+ if(.not.evencopy(i)%lstate) cycle
+ if(abs(evencopy(i)%freq-f1).lt.3.0 .and. abs(evencopy(i)%dt-xdt).lt.0.19) then
+ msgd=evencopy(i)%msg
+ lsd=.true.
+ isd=i
+ if(msgd(1:3).eq.'CQ ' .or. msgd(1:3).eq.'DE ' .or. &
+ msgd(1:4).eq.'QRZ ') lcq=.true.
+ endif
+ enddo
+ elseif(loddint) then
+ do i=1,130
+ if(.not.oddcopy(i)%lstate) cycle
+ if(abs(oddcopy(i)%freq-f1).lt.3.0 .and. abs(oddcopy(i)%dt-xdt).lt.0.19) then
+ msgd=oddcopy(i)%msg
+ lsd=.true.
+ isd=i
+ if(msgd(1:3).eq.'CQ ' .or. msgd(1:3).eq.'DE ' .or. &
+ msgd(1:4).eq.'QRZ ') lcq=.true.
+ endif
+ enddo
+ endif
+
+ if(lsd .and. nqso.eq.1) nqso=4
+
+!nlasttx last TX message
+! 0 Tx was halted
+! 1 AA1AA BB1BB PL35
+! 2 AA1AA BB1BB -15
+! 3 AA1AA BB1BB R-15
+! 4 AA1AA BB1BB RRR/RR73
+! 5 AA1AA BB1BB 73
+! 6 CQ BB1BB PL35
+
+ if(nqso.eq.4) cd1=cd0
+ do iqso=1,nqso
+ lapcqonly=.false.
+ if(iqso.gt.1 .and. iqso.lt.4 .and. nqso.eq.4) cycle
+ if(xdt0.lt.-4.9 .or. xdt0.gt.4.9) cycle
+ if(lvirtual2 .and. iqso.ne.2) cycle
+ if(lvirtual3 .and. iqso.lt.2) cycle
+ if((lvirtual2 .or. lvirtual3) .and. nft8rxfsens.lt.3 .and. iqso.eq.3) cycle
+ lastsync=.false.
+ lsdone=.false.
+ if(.not.lvirtual2 .and. .not.lvirtual3 .and. iqso.eq.2) then
+ cd0=cd2
+ elseif(lvirtual2 .and. iqso.eq.2) then
+ cd0=cd2
+ elseif(lvirtual3 .and. iqso.eq.2) then
+ cd0=cd3
+ endif
+ if(iqso.eq.4) then
+ call tonesdvar(msgd,lcq)
+ if(.not.ldeepsync) go to 32
+ cd0=cd1
+ endif
+ if(iqso.eq.3) go to 16
+ i0=nint((xdt0+0.5)*fs2) !Initial guess for start of signal
+ smax=0.0
+ ctwk=cmplx(1.0,0.0)
+ do idt=i0-8,i0+8 !Search over +/- one quarter symbol
+ call sync8dvar(cd0,idt,ctwk,0,sync,ipass,lastsync,iqso,lcq,lcallsstd,lcqcand)
+ if(sync.gt.smax) then
+ smax=sync
+ ibest=idt
+ endif
+ enddo
+ xdt2=ibest*dt2 !Improved estimate for DT
+
+ ! Now peak up in frequency
+ i0=nint(xdt2*fs2)
+ smax=0.0
+ kstep=1
+ do ifr=-5,5
+ if(iqso.eq.1 .or. iqso.eq.4) then
+ ctwk=ctwkw(kstep,:)
+ delf=ifr*0.5 ! Search over +/- 2.5 Hz
+ else
+ ctwk=ctwkn(kstep,:)
+ delf=ifr*0.25 ! Search over +/- 1.25 Hz
+ endif
+ call sync8dvar(cd0,i0,ctwk,1,sync,ipass,lastsync,iqso,lcq,lcallsstd,lcqcand)
+ if(sync.gt.smax) then
+ smax=sync
+ delfbest=delf
+ endif
+ kstep=kstep+1
+ enddo
+ a=0.0
+ a(1)=-delfbest
+ call twkfreq1var(cd0,-800,3199,4000,fs2,a,cd0)
+ xdt=xdt2
+ f1=f10+delfbest !Improved estimate of DF
+ dfqso=abs(nfqso-f1)
+ lastsync=.true.
+ call sync8dvar(cd0,i0,ctwk,2,sync,ipass,lastsync,iqso,lcq,lcallsstd,lcqcand)
+
+16 if(iqso.eq.3) ibest=ibest+1
+
+ syncav=3.
+ syncavpart=3.
+ snrsync=0.
+ do k=1,79
+ i1=ibest+(k-1)*32
+ csymb=cd0(i1:i1+31)
+ if((k.ge.1 .and. k.le.7) .or. (k.ge.37 .and. k.le.43) .or. &
+ (k.ge.73 .and. k.le.79)) then
+ call four2avar(csymb,32,1,-1,1)
+ s81(0:7)=abs(csymb(1:8))
+ if(k.ge.1 .and. k.le.7) then
+ synclev=s81(icos7(k-1))
+ snoiselev=(sum(s81)-synclev)/7.0
+ if(snoiselev.gt.1.E-16) snrsync(k)=synclev/snoiselev
+ else if(k.ge.37 .and. k.le.43) then
+ synclev=s81(icos7(k-37))
+ snoiselev=(sum(s81)-synclev)/7.0
+ if(snoiselev.gt.1.E-16) snrsync(k-29)=synclev/snoiselev
+ else if(k.ge.73 .and. k.le.79) then
+ synclev=s81(icos7(k-73))
+ snoiselev=(sum(s81)-synclev)/7.0
+ if(snoiselev.gt.1.E-16) snrsync(k-58)=synclev/snoiselev
+ endif
+ else
+ cycle
+ endif
+ enddo
+
+ syncav=sum(snrsync)/21.
+ syncavpart(1)=sum(snrsync(1:7))/7.
+ syncavpart(2)=sum(snrsync(8:14))/7.
+ syncavpart(3)=sum(snrsync(15:21))/7.
+ syncavemax=maxval(syncavpart,1)
+
+! plev=0.0
+! do k=1000,1009; abscd=abs(cd0(k)); if(abscd.gt.plev) plev=abscd; enddo
+! plev=plev/61.0
+! do k=0,3199; xx=plev*gran(); yy=plev*gran(); cd0(k)=cd0(k) + complex(xx,yy); enddo
+
+ lreverse=.false.
+ if(nft8cycles.lt.2) then
+ if(ipass.eq.2) lreverse=.true.
+ else
+ if(ipass.eq.5 .or. ipass.eq.7) lreverse=.true.
+ endif
+
+ do k=1,79
+ i1=ibest+(k-1)*32
+ csymb=cd0(i1:i1+31)
+ if(syncav.lt.2.5) then
+ csymb(1)=csymb(1)*1.9
+ csymb(32)=csymb(32)*1.9
+ scr=SQRT(abs(csymb(1)))/SQRT(abs(csymb(32)))
+ if(scr.gt.1.0) then
+ csymb(32)=csymb(32)*scr
+ else
+ if(scr.gt.1.E-16) csymb(1)=csymb(1)/scr
+ endif
+ endif
+ do i=1,32
+ csymbr(i)=cmplx(real(csymb(33-i)),-aimag(csymb(33-i)))
+ enddo
+ if(lreverse) then
+ call four2avar(csymb,32,1,-1,1)
+ cscs(0:7,k)=csymb(1:8)/1e3
+ csymb=csymbr
+ endif
+ call four2avar(csymb,32,1,-1,1)
+ cs(0:7,k)=csymb(1:8)/1e3
+ if(lreverse) then
+ csr=cs
+ else
+ call four2avar(csymbr,32,1,-1,1)
+ csr(0:7,k)=csymbr(1:8)/1e3
+ endif
+ s8(0:7,k)=abs(csymb(1:8))
+ enddo
+
+ sp=0.
+ do k=0,7
+ sp(k)=sum(s8(k,1:7))+sum(s8(k,18:79))
+ enddo
+ ka=minloc(sp)-1
+ k=ka(1)
+ if(k.lt.0) go to 128
+ do kb=0,7
+ if(kb.eq.k) cycle
+ spr=sp(kb)/sp(k)
+ if(spr.gt.1.5) then
+ s8(kb,:)=s8(kb,:)/spr
+ sprsqr=SQRT(spr)
+ cs(kb,:)=cs(kb,:)/sprsqr
+ csr(kb,:)=csr(kb,:)/sprsqr
+ cscs(kb,:)=cscs(kb,:)/sprsqr
+ endif
+ enddo
+128 continue
+
+ if(iqso.gt.1 .and. iqso.lt.4) then
+ s82=SQRT(s8)
+ go to 8
+ endif
+ if(iqso.eq.4) go to 32
+
+ nsyncscorew=0
+ scoreratiowa=0.
+ rrxdt=xdt-0.5
+ if(rrxdt.ge.-0.5 .and. rrxdt.le.2.13) then
+ do k=1,7
+ syncw(icos7(k-1)+1)=s8(icos7(k-1),k)+s8(icos7(k-1),k+36) + &
+ s8(icos7(k-1),k+72)
+ enddo
+ do k=1,7
+ sumkw(k)=(sum(s8(k-1,:))-syncw(k))/25.333
+ enddo ! (79-3)/3
+ else if(rrxdt.lt.-0.5) then
+ do k=1,7
+ syncw(icos7(k-1)+1)=s8(icos7(k-1),k+36)+s8(icos7(k-1),k+72)
+ enddo
+ do k=1,7
+ sumkw(k)=(sum(s8(k-1,26:79))-syncw(k))/26.
+ enddo ! (54-2)/2
+ else if(rrxdt.gt.2.13) then
+ do k=1,7
+ syncw(icos7(k-1)+1)=s8(icos7(k-1),k)+s8(icos7(k-1),k+36)
+ enddo
+ do k=1,7
+ sumkw(k)=(sum(s8(k-1,1:54))-syncw(k))/26.
+ enddo ! (54-2)/2
+ endif
+ do k=1,7
+ if(syncw(k).gt.sumkw(k)) nsyncscorew=nsyncscorew+1
+ scoreratiow(k)=syncw(k)/sumkw(k)
+ enddo
+ scoreratiowa=sum(scoreratiow)/7.
+
+! sync quality check
+ is1=0
+ is2=0
+ is3=0
+ nsyncscore=0
+ nsyncscore1=0
+ nsyncscore2=0
+ nsyncscore3=0
+ scoreratio=0.
+ scoreratio1=0.
+ scoreratio2=0.
+ scoreratio3=0.
+ nsync2=0
+ do k=1,7
+ s81(:)=s8(:,k)
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ is1=is1+1
+ else
+ s81(ip(1)-1)=0.
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) nsync2=nsync2+1
+ endif
+ s81=s8(:,k+36)
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ is2=is2+1
+ else
+ s81(ip(1)-1)=0.
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) nsync2=nsync2+1
+ endif
+ s81=s8(:,k+72)
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ is3=is3+1
+ else
+ s81(ip(1)-1)=0.
+ ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) nsync2=nsync2+1
+ endif
+ if(rrxdt.ge.-0.5) then
+ synck=s8(icos7(k-1),k)
+ sumk=(sum(s8(:,k))-synck)/7.0
+ if(synck.gt.sumk) then
+ nsyncscore1=nsyncscore1+1
+ scoreratio1=scoreratio1+synck/sumk
+ endif
+ endif
+ synck=s8(icos7(k-1),k+36)
+ sumk=(sum(s8(:,k+36))-synck)/7.0
+ if(synck.gt.sumk) then
+ nsyncscore2=nsyncscore2+1
+ scoreratio2=scoreratio2+synck/sumk
+ endif
+ if(rrxdt.le.2.13) then
+ synck=s8(icos7(k-1),k+72)
+ sumk=(sum(s8(:,k+72))-synck)/7.0
+ if(synck.gt.sumk) then
+ nsyncscore3=nsyncscore3+1
+ scoreratio3=scoreratio3+synck/sumk
+ endif
+ endif
+ enddo
+ nsyncscore=nsyncscore1+nsyncscore2+nsyncscore3
+ scoreratio=scoreratio1+scoreratio2+scoreratio3
+! hard sync sum - max is 21
+ nsync=is1+is2+is3
+! bail out
+ rscq=0.
+ if(lcqcand) then
+ do k11=8,16
+ ip=maxloc(s8(:,k11))
+ if(k11.lt.16) then
+ if(ip(1).eq.1) rscq=rscq+1.
+ else
+ if(ip(1).eq.2) rscq=rscq+1.
+ endif
+ enddo
+ ip=maxloc(s8(:,17))
+ if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+ ip=maxloc(s8(:,27))
+ if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+ ip=maxloc(s8(:,33))
+ if(ip(1).eq.3 .or. ip(1).eq.4) rscq=rscq+0.5
+ endif
+ if(lcqcand .and. nsync.eq.4) then
+ if(nsync+nsync2.lt.12) then
+ if(rscq.lt.6.6) then
+ nbadcrc=1
+ return
+ endif
+ endif
+ lapcqonly=.true.
+ else if(lcqcand .and. nsync.eq.5) then
+ if(nsync+nsync2.lt.12) then
+ if(rscq.lt.6.1) then
+ nbadcrc=1
+ return
+ endif
+ endif
+ lapcqonly=.true.
+ else if(lcqcand .and. nsync.eq.6) then
+ if(nsync+nsync2.lt.11) then
+ if(rscq.lt.5.6) then
+ nbadcrc=1
+ return
+ endif
+ endif
+ lapcqonly=.true.
+ else
+ if(nsync.lt.7) then
+ nbadcrc=1
+ return
+ endif
+ endif
+
+ lskipnotap=.false.
+ if(.not.lapcqonly .and. nsync.lt.11) then
+ nsmax=0
+ do k=1,7
+ s81=s8(:,k)
+ include 'syncdist.f90'
+ s81=s8(:,k+36)
+ include 'syncdist.f90'
+ s81=s8(:,k+72)
+ include 'syncdist.f90'
+ enddo
+ if(sum(nsmax(7:8)).gt.sum(nsmax(2:3)) .or. &
+ sum(nsmax(5:6)).gt.sum(nsmax(2:3))) lskipnotap=.true.
+ endif
+
+! if(lcqcand .and. nsync.lt.7 .and. nsync.gt.1) then
+! if(nsync+nsync2.lt.9) then
+! rscq=0.
+! do k11=8,16
+! ip=maxloc(s8(:,k11))
+! if(k11.lt.16) then; if(ip(1).eq.1) rscq=rscq+1.; else; if(ip(1).eq.2) rscq=rscq+1.; endif
+! enddo
+! ip=maxloc(s8(:,17)); if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+! ip=maxloc(s8(:,27)); if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+! ip=maxloc(s8(:,33)); if(ip(1).eq.3 .or. ip(1).eq.4) rscq=rscq+0.5
+! if(rscq.lt.4.9) then; nbadcrc=1; return; endif
+! endif
+! else
+! if(nsync.lt.7) then; nbadcrc=1; return; endif
+! endif
+
+ if(nsyncscore.gt.0) then
+ scoreratio=scoreratio/nsyncscore
+ else
+ scoreratio=0.
+ endif
+ if(nsyncscore1.gt.0) then
+ scoreratio1=scoreratio1/nsyncscore1
+ else
+ scoreratio1=0.
+ endif
+ if(nsyncscore3.gt.0) then
+ scoreratio3=scoreratio3/nsyncscore3
+ else
+ scoreratio3=0.
+ endif
+
+ if(dfqso.ge.2.0 .or. (dfqso.lt.2.0 .and. stophint)) then
+ if(rrxdt.ge.-0.5 .and. rrxdt.le.2.13) then
+ if(nsyncscore.lt.8 .or. (nsyncscore.lt.10 .and. scoreratio.lt.5.5) .or. &
+ (nsyncscore.lt.11 .and. scoreratio.lt.3.63)) then
+ nbadcrc=1
+ return ! 377 out of 20709
+ else if(nsyncscore.eq.11 .and. scoreratio.lt.5.37) then
+ if(nsyncscore1.lt.5 .and. nsyncscore3.lt.5 .and. scoreratio1.lt.4.2 &
+ .and. scoreratio3.lt.4.2) then
+ nbadcrc=1
+ return ! 261
+ endif
+ else if(nsyncscore.eq.12 .and. scoreratio.lt.4.6) then
+ if(nsyncscore1.lt.5 .and. nsyncscore3.lt.5 .and. scoreratio1.lt.4.0 &
+ .and. scoreratio3.lt.4.0) then
+ nbadcrc=1
+ return ! 222
+ endif
+ else if(nsyncscore.eq.13 .and. scoreratio.lt.4.4) then
+ if(nsyncscore1.lt.5 .and. nsyncscore2.lt.6 .and. nsyncscore3.lt.5 &
+ .and. scoreratio1.lt.4.4 .and. scoreratio3.lt.4.4) then
+ nbadcrc=1
+ return ! 98
+ endif
+ else if(nsyncscorew.lt.3) then
+ if((nsyncscore1.gt.5 .and. scoreratio1.gt.13.8) .or. &
+ (nsyncscore2.gt.5 .and. scoreratio2.gt.13.8) .or. &
+ (nsyncscore3.gt.5 .and. scoreratio3.gt.13.8)) go to 32
+ nbadcrc=1
+ return ! 75
+ else if(nsyncscorew.eq.3) then
+ if(scoreratio1.gt.15. .or. scoreratio2.gt.15. .or. scoreratio3.gt.15.) &
+ go to 32
+ nbadcrc=1
+ return ! 125
+ else if(nsyncscorew.eq.4) then
+ if(nsyncscore1.eq.7 .or. nsyncscore2.eq.7 .or. nsyncscore3.eq.7 .or. &
+ scoreratio1.gt.10. .or. scoreratio2.gt.10. .or. &
+ scoreratio3.gt.10.) go to 32
+ nbadcrc=1
+ return ! 94
+ else if(nsyncscorew.eq.5) then
+ if(nsyncscore.gt.17 .or. nsyncscore1.eq.7 .or. nsyncscore2.eq.7 .or. &
+ nsyncscore3.eq.7 .or. scoreratio1.gt.10. .or. &
+ scoreratio2.gt.10. .or. scoreratio3.gt.10.) go to 32
+ nbadcrc=1
+ return ! 131
+ endif
+ else if(rrxdt.lt.-0.5) then
+ if(nsyncscore.lt.6 .or. (nsyncscore.gt.5 .and. nsyncscore.lt.8 .and. &
+ nsyncscorew.lt.6 .and. scoreratio2.lt.5.5 .and. &
+ scoreratio3.lt.5.5)) then
+ nbadcrc=1
+ return ! 46
+ else if(nsyncscore.eq.8) then
+ if(nsyncscore2.lt.6 .and. nsyncscore3.lt.6 .and. scoreratio2.lt.6.6 &
+ .and. scoreratio3.lt.6.6) then
+ nbadcrc=1
+ return ! 20
+ endif
+ else if(nsyncscore.eq.9 .and. scoreratio.lt.6.0) then
+ if(nsyncscore2.lt.6 .and. nsyncscore3.lt.6 .and. scoreratio2.lt.6.6 &
+ .and. scoreratio3.lt.6.5) then
+ nbadcrc=1
+ return ! 5
+ endif
+ else if(nsyncscorew.lt.3) then
+ if((nsyncscore2.gt.5 .and. scoreratio2.gt.13.8) .or. &
+ (nsyncscore3.gt.5 .and. scoreratio3.gt.13.8)) go to 32
+ nbadcrc=1
+ return ! 22
+ else if(nsyncscorew.eq.3) then
+ if(scoreratio2.gt.15. .or. nsyncscore3.gt.15) go to 32
+ nbadcrc=1
+ return ! 31
+ else if(nsyncscorew.eq.4) then
+ if(nsyncscore2.eq.7 .or. nsyncscore3.eq.7 .or. scoreratio2.gt.10. &
+ .or. nsyncscore3.gt.10) go to 32
+ nbadcrc=1
+ return ! 34
+ else if(nsyncscorew.eq.5) then
+ if(nsyncscore.gt.11 .or. nsyncscore2.eq.7 .or. nsyncscore3.eq.7 &
+ .or. scoreratio2.gt.10. .or. scoreratio3.gt.10.) go to 32
+ nbadcrc=1
+ return ! 35
+ endif
+ else if(rrxdt.gt.2.13) then
+ if(nsyncscore.lt.6 .or. (nsyncscore.gt.5 .and. nsyncscore.lt.8 .and. &
+ nsyncscorew.lt.6 .and. scoreratio1.lt.5.5 .and. &
+ scoreratio2.lt.5.5)) then
+ nbadcrc=1
+ return ! 4
+ else if(nsyncscore.eq.8) then
+ if(nsyncscore1.lt.6 .and. nsyncscore2.lt.6 .and. scoreratio1.lt.6.6 &
+ .and. scoreratio2.lt.6.6) then
+ nbadcrc=1
+ return ! 8
+ endif
+ else if(nsyncscore.eq.9 .and. scoreratio.lt.6.0) then
+ if(nsyncscore1.lt.6 .and. nsyncscore2.lt.6 .and. scoreratio2.lt.6.6 &
+ .and. scoreratio1.lt.6.5) then
+ nbadcrc=1
+ return ! 2
+ endif
+ else if(nsyncscorew.lt.3) then
+ if((nsyncscore1.gt.5 .and. scoreratio1.gt.13.8) .or. &
+ (nsyncscore2.gt.5 .and. scoreratio2.gt.13.8)) go to 32
+ nbadcrc=1
+ return ! 12
+ else if(nsyncscorew.eq.3) then
+ if(scoreratio1.gt.15. .or. scoreratio2.gt.15.) go to 32
+ nbadcrc=1
+ return ! 32
+ else if(nsyncscorew.eq.4) then
+ if(nsyncscore1.eq.7 .or. nsyncscore2.eq.7 .or. scoreratio1.gt.10. &
+ .or. nsyncscore2.gt.10) go to 32
+ nbadcrc=1
+ return ! 103
+ else if(nsyncscorew.eq.5) then
+ if(nsyncscore.gt.11 .or. nsyncscore1.eq.7 .or. nsyncscore2.eq.7 &
+ .or. scoreratio1.gt.10. .or. scoreratio2.gt.10.) go to 32
+ nbadcrc=1
+ return ! 0
+ endif
+ endif
+ endif
+
+32 if(lsd) then
+ if(iqso.eq.4 .and. .not.ldeepsync) go to 64
+ call ft8sd1var(s8,itone,msgd,msg37,lft8sd,lcq)
+ if(lft8sd) then
+ if(levenint) then
+ evencopy(isd)%lstate=.false.
+ elseif(loddint) then
+ oddcopy(isd)%lstate=.false.
+ endif
+ i3=1
+ n3=1
+ iaptype2=iaptype
+ iaptype=0
+ nbadcrc=0
+ lsd=.false.
+ go to 2
+ endif
+
+64 if(iqso.eq.4) then
+ if(.not.lcq) then
+ call ft8mf1var(s8,itone,msgd,msg37,lft8sd)
+ if(lft8sd) then
+ if(levenint) then
+ evencopy(isd)%lstate=.false.
+ elseif(loddint) then
+ oddcopy(isd)%lstate=.false.
+ endif
+ i3=1
+ n3=1
+ iaptype2=iaptype
+ iaptype=0
+ nbadcrc=0
+ lsd=.false.
+ go to 2
+ endif
+ else
+ call ft8mfcqvar(s8,itone,msgd,msg37,lft8sd)
+ if(lft8sd) then
+ if(levenint) then
+ evencopy(isd)%lstate=.false.
+ elseif(loddint) then
+ oddcopy(isd)%lstate=.false.
+ endif
+ i3=1
+ n3=1
+ iaptype2=iaptype
+ iaptype=0
+ nbadcrc=0
+ lsd=.false.
+ go to 2
+ endif
+ endif
+ endif
+ endif
+
+ if(iqso.eq.4) then
+ nbadcrc=1
+ go to 2
+ endif
+
+ synclev=0.0
+ snoiselev=1.0
+ do k=1,7
+ synclev=synclev+s8(icos7(k-1),k+36)
+ enddo
+ snoiselev=(sum(s8(0:7,37:43))- synclev)/7.0
+ if(snoiselev.lt.0.1) snoiselev=1.0 ! safe division
+ srr=synclev/snoiselev
+
+! SNR srr range average srr
+! -18 1.8...4.0 2.9
+! -19 1.7...3.6 2.65
+! -20 1.6...3.3 2.43
+! -21 1.6...3.0 2.22
+! -22 1.55...2.8 2.19
+! -23 1.4...2.6 2.03
+! -24 1.94
+
+8 if(iqso.gt.1 .and. iqso.lt.4) then
+ if(.not.lqsomsgdcd .and. .not.(.not.lmycallstd .and. .not.lhiscallstd)) then
+ if(.not.lft8sdec .and. dfqso.lt.2.0) then
+ if(lvirtual2 .or. lvirtual3) srr=0.0
+ call ft8svar(s82,srr,itone,msg37,lft8s,nft8rxfsens,stophint)
+ if(lft8s) then
+ if(index(msg37,'<').gt.0) then
+ lhashmsg=.true.
+ endif
+ nbadcrc=0
+ lft8sdec=.true.
+ lsdone=.true.
+ go to 2 ! i3=16 n3=16, any affect?
+ endif
+ endif
+ endif
+ lsdone=.true.
+ nbadcrc=1
+ cycle
+ endif
+
+ i1=ibest+224 ! 7*32
+ csymb256=cd0(i1:i1+255)*ctwk256
+ call four2avar(csymb256,256,1,-1,1)
+ s256(0:8)=abs(csymb256(1:9))
+ rscq=0.
+ nmic=0
+ do k11=8,16
+ ip=maxloc(s8(:,k11))
+ if(ip(1).eq.idtonemyc(k11-7)+1) nmic=nmic+1
+ if(k11.lt.16) then
+ if(ip(1).eq.1) rscq=rscq+1.
+ else
+ if(ip(1).eq.2) rscq=rscq+1.
+ endif
+ enddo
+ ip=maxloc(s8(:,17))
+ if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+ ip=maxloc(s8(:,27))
+ if(ip(1).eq.1 .or. ip(1).eq.2) rscq=rscq+0.5
+ ip=maxloc(s8(:,33))
+ if(ip(1).eq.3 .or. ip(1).eq.4) rscq=rscq+0.5
+
+ lqsosig=.false.
+ lqsosigtype3=.false.
+ lqso73=.false.
+ lqsorr73=.false.
+ lqsorrr=.false. ! 73/rr73/rrr for std/nonstd callsigns
+ if(.not.lqsomsgdcd .and. (dfqso.lt.napwid .or. abs(nftx-f1).lt.napwid) .and. &
+ lapmyc .and. len_trim(hiscall).gt.2) then
+ nqsot=0
+ do i=1,19
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtone56(1,i)+1) nqsot=nqsot+1
+ enddo
+ if(nqsot.gt.6) lqsosig=.true. ! decoding depth only
+ do i=20,22
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtone56(1,i)+1) nqsot=nqsot+1
+ enddo
+ if(nqsot.gt.3) lqsosigtype3=.true.
+ nqsoend=0 ! array 73,rr73,rrr
+ if(dfqso.lt.napwid .and. (nQSOProgress.eq.3 .or. nQSOProgress.eq.4)) then
+ ! QSO RX freq only
+ do i=24,58
+ if(i.lt.30) then
+ ip=maxloc(s8(:,i+7))
+ else
+ ip=maxloc(s8(:,i+14))
+ endif
+ if(ip(1).eq.idtone56(56,i)+1) nqsoend(1)=nqsoend(1)+1
+ if(ip(1).eq.idtone56(55,i)+1) nqsoend(2)=nqsoend(2)+1
+ if(ip(1).eq.idtone56(54,i)+1) nqsoend(3)=nqsoend(3)+1
+ enddo
+ ip=maxloc(nqsoend)
+ if(nqsoend(ip(1)).gt.6) then
+ if(ip(1).eq.1) then
+ lqso73=.true.
+ else if(ip(1).eq.2) then
+ lqsorr73=.true.
+ else if(ip(1).eq.3) then
+ lqsorrr=.true.
+ endif
+ endif
+ endif
+ endif
+
+ lcqsignal=.false.
+ ip(1)=maxloc(s256,1)
+ if(ip(1).eq.5 .or. rscq.gt.3.1) lcqsignal=.true.
+ if(.not.lcqsignal .and. ip(1).eq.4 .or. ip(1).eq.6) then
+ s2563(0:8)=s256(0:8)
+ s2563(9:26)=abs(csymb256(9:26))
+ ip(1)=maxloc(s2563,1)
+ if(ip(1).eq.4 .or. ip(1).eq.6) lcqsignal=.true.
+ endif
+ lmycsignal=.false.
+ if(lapmyc .and. nmic.gt.2) lmycsignal=.true.
+
+ ldxcsig=.false.
+ lcqdxcsig=.false.
+ lcqdxcnssig=.false.
+ ndxt=0
+ if(lhiscallstd) then
+ do k11=17,26
+ ip=maxloc(s8(:,k11))
+ if(ip(1).eq.idtone56(1,k11-7)+1) ndxt=ndxt+1
+ enddo
+ if(ndxt.gt.3) ldxcsig=.true.
+ if(lcqsignal .and. ldxcsig) lcqdxcsig=.true.
+ endif
+! nonstd DXCall search in idle mode
+ if(.not.lhiscallstd .and. len_trim(hiscall).gt.2) then ! nonstandard DXCall
+ ncqdxcnst=0
+ do i=1,4
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtonecqdxcns(i)+1) ncqdxcnst=ncqdxcnst+1
+ enddo
+ ndxt=0
+ do i=5,23
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtonedxcns73(i)+1) ndxt=ndxt+1
+ if(ip(1).eq.idtonecqdxcns(i)+1) ncqdxcnst=ncqdxcnst+1
+ enddo
+ ldxcsig=.false.
+ if(dfqso.lt.napwid) then
+ if(ndxt.gt.4) ldxcsig=.true. ! relaxed threshold for RXF napwid
+ if(ncqdxcnst.gt.5) lcqdxcnssig=.true.
+ else
+ if(ndxt.gt.5) ldxcsig=.true.
+ if(ncqdxcnst.gt.6) lcqdxcnssig=.true.
+ endif
+ endif
+
+ lfoxstdr73=.false.
+ lfoxspecrpt=.false.
+ nfoxspecrpt=0 ! checking fo special message with report to mybcall
+ if(lhound) then
+ nfoxstdbase=0 ! checking for report signal and base of RR73 signal
+ nfoxspecr73=0 ! checking fo special message with RR73 to mybcall
+ nfoxr73=0 ! checking for RR73 signal with standard message
+ fdelta=abs(f1-nfqso)
+ fdeltam=modulo(fdelta,60.)
+ if(fdelta.lt.245.0 .and. fdeltam.lt.3.0 .and. (nQSOProgress.eq.1 .or. &
+ nQSOProgress.eq.3)) then ! calculate on possible Fox frequencies only
+ do i=1,18
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtonefox73(i)+1) nfoxstdbase=nfoxstdbase+1
+ if(i.gt.10 .and. ip(1).eq.idtonespec(i)+1) nfoxspecrpt=nfoxspecrpt+1
+ enddo
+ do i=20,22 ! hash10
+ ip=maxloc(s8(:,i+7))
+ if(ip(1).eq.idtonespec(i)+1) then
+ nfoxspecrpt=nfoxspecrpt+1
+ nfoxspecr73=nfoxspecr73+1
+ endif
+ enddo
+ ip=maxloc(s8(:,25+7)) ! i3,n3
+ if(ip(1).eq.idtonespec(25)+1) then
+ nfoxspecrpt=nfoxspecrpt+1
+ nfoxspecr73=nfoxspecr73+1
+ endif
+ if(nfoxstdbase.eq.0) then
+ rspecstdrpt=(nfoxspecrpt*18.)/(1.2)
+ else
+ rspecstdrpt=(nfoxspecrpt*18.)/(12.*nfoxstdbase)
+ endif
+ if(rspecstdrpt.gt.1.) lfoxspecrpt=.true.
+ if(nQSOProgress.eq.3) then
+ do i=24,58
+ if(i.lt.30) then
+ ip=maxloc(s8(:,i+7))
+ else
+ ip=maxloc(s8(:,i+14))
+ endif
+ if(ip(1).eq.idtonefox73(i)+1) nfoxr73=nfoxr73+1
+ enddo
+ if(nfoxspecr73.eq.0) then
+ rstdr73=(nfoxr73*4.)/(3.5)
+ else
+ rstdr73=(nfoxr73*4.)/(35.*nfoxspecr73)
+ endif
+ if(rstdr73.gt.1.) lfoxstdr73=.true.
+ endif
+ endif
+ endif
+
+ lsubptxfreq=.false.
+ if(lapmyc .and. abs(f1-nftx).lt.2.0 .and. .not.lhound .and. .not.lft8sdec &
+ .and. .not.lqsomsgdcd .and. ((.not.lskiptx1 .and. nlasttx.eq.1) .or. &
+ (lskiptx1 .and. nlasttx.eq.2))) lsubptxfreq=.true.
+
+ nweak=1
+ if(lft8subpass .or. dfqso.lt.2.0 .or. lsubptxfreq) nweak=2
+ nsubpasses=nweak
+ if(lcqsignal) then
+ nsubpasses=3
+ if(levenint) then
+ do ik=1,numcqsig
+ if(evencq(ik,nthr)%freq.gt.5001.) exit
+ if(abs(evencq(ik,nthr)%freq-f1).lt.2.0 .and. &
+ abs(evencq(ik,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=5
+ csold=evencq(ik,nthr)%cs
+ endif
+ enddo
+ else if (loddint) then
+ do ik=1,numcqsig
+ if(oddcq(ik,nthr)%freq.gt.5001.) exit
+ if(abs(oddcq(ik,nthr)%freq-f1).lt.2.0 .and. &
+ abs(oddcq(ik,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=5
+ csold=oddcq(ik,nthr)%cs
+ endif
+ enddo
+ endif
+ endif
+ if(lmycsignal .and. lmycallstd) then
+ nsubpasses=6
+ if(levenint) then
+ do ik=1,nummycsig
+ if(evenmyc(ik,nthr)%freq.gt.5001.) exit
+ if(abs(evenmyc(ik,nthr)%freq-f1).lt.2.0 .and. &
+ abs(evenmyc(ik,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=8
+ csold=evenmyc(ik,nthr)%cs
+ endif
+ enddo
+ else if (loddint) then
+ do ik=1,nummycsig
+ if(oddmyc(ik,nthr)%freq.gt.5001.) exit
+ if(abs(oddmyc(ik,nthr)%freq-f1).lt.2.0 .and. &
+ abs(oddmyc(ik,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=8
+ csold=oddmyc(ik,nthr)%cs
+ endif
+ enddo
+ endif
+ endif
+ lqsocandave=.false.
+ if(lapmyc .and. ndxt.gt.2 .and. nmic.gt.2 .and. .not.lqsomsgdcd .and. &
+ lmycallstd .and. lhiscallstd .and. dfqso.lt.napwid/2.0) then
+ lqsocandave=.true.
+ nsubpasses=9
+ if(levenint) then
+ if(abs(evenqso(1,nthr)%freq-f1).lt.2.0 .and. &
+ abs(evenqso(1,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=11
+ csold=evenqso(1,nthr)%cs
+ endif
+ else if (loddint) then
+ if(abs(oddqso(1,nthr)%freq-f1).lt.2.0 .and. &
+ abs(oddqso(1,nthr)%xdt-xdt).lt.0.05) then
+ nsubpasses=11
+ csold=oddqso(1,nthr)%cs
+ endif
+ endif
+ endif
+
+ do isubp1=1,nsubpasses
+ if(nweak.eq.1 .and. isubp1.eq.2) cycle
+
+ ! skip if it is lmycsignal, can be both lcq and lmy
+ if(isubp1.gt.2 .and. isubp1.lt.6 .and. lmycsignal) cycle
+
+ syncavemax=3.
+ if(isubp1.eq.2) cs=csr
+ if(ipass.eq.npass-1 .and. (lcqsignal .or. lmycsignal) .and. &
+ ((nweak.eq.1 .and. isubp1.eq.1) .or. (nweak.eq.2 .and. &
+ isubp1.eq.2))) cstmp2=cs
+ if(ipass.eq.npass .and. lapmyc .and. ndxt.gt.2 .and. nmic.gt.2 .and. &
+ ((nweak.eq.1 .and. isubp1.eq.1) .or. &
+ (nweak.eq.2 .and. isubp1.eq.2))) cstmp2=cs
+ do nsym=1,3
+ nt=2**(3*nsym)-1
+ do ihalf=1,2
+ do k=1,29,nsym
+ if(ihalf.eq.1) then
+ ks=k+7
+ else
+ ks=k+43
+ endif
+ ks1=ks+1
+ ks2=ks+2
+ do i=0,nt
+ i1=i/64
+ i2=iand(i,63)/8
+ i33=iand(i,7)
+ if(isubp1.lt.3) then
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i33),ks))
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i33),ks1))
+ else
+ s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks1) + &
+ cs(graymap(i33),ks2))
+ endif
+ else if(isubp1.eq.3 .or. isubp1.eq.6 .or. isubp1.eq.9) then
+ if(nsym.eq.1) then
+ s2(i)=abs(cscs(graymap(i33),ks))**2 + &
+ abs(csr(graymap(i33),ks))**2
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cscs(graymap(i2),ks) + &
+ cscs(graymap(i33),ks1))**2 + &
+ abs(csr(graymap(i2),ks)+csr(graymap(i33),ks1))**2
+ else
+ s2(i)=abs(cscs(graymap(i1),ks) + &
+ cscs(graymap(i2),ks1)+cscs(graymap(i33),ks2))**2 + &
+ abs(csr(graymap(i1),ks)+csr(graymap(i2),ks1) + &
+ csr(graymap(i33),ks2))**2
+ endif
+ else if(isubp1.eq.4 .or. isubp1.eq.7 .or. isubp1.eq.10) then
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i33),ks))**2 + &
+ abs(csold(graymap(i33),ks))**2
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i33),ks1))**2 + &
+ abs(csold(graymap(i2),ks)+csold(graymap(i33),ks1))**2
+ else
+ s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks1) + &
+ cs(graymap(i33),ks2))**2 + &
+ abs(csold(graymap(i1),ks)+csold(graymap(i2),ks1) + &
+ csold(graymap(i33),ks2))**2
+ endif
+ else if(isubp1.eq.5 .or. isubp1.eq.8 .or. isubp1.eq.11) then
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i33),ks))+abs(csold(graymap(i33),ks))
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i33),ks1)) + &
+ abs(csold(graymap(i2),ks)+csold(graymap(i33),ks1))
+ else
+ s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks1) + &
+ cs(graymap(i33),ks2)) + &
+ abs(csold(graymap(i1),ks)+csold(graymap(i2),ks1) + &
+ csold(graymap(i33),ks2))
+ endif
+ endif
+ if(isubp1.eq.1 .and. srr.lt.2.5) then
+ ! srr.lt.2.5 -19dB SNR threshold
+ if(srr.gt.2.3) then
+ s2(i)=s2(i)**2
+ else
+ ss1=s2(i)
+ if(ss1.lt.5.77) then
+ s2(i)=1+8.*ss1**2-0.12*ss1**4
+ else
+ s2(i)=(ss1+5.82)**2
+ endif
+ endif
+ endif
+ if(isubp1.gt.1 .and. srr.lt.2.5) then
+ s2(i)=(0.5*s2(i))**3 ! -19dB SNR threshold
+ endif
+ enddo
+ i32=1+(k-1)*3+(ihalf-1)*87
+ if(nsym.eq.1) ibmax=2
+ if(nsym.eq.2) ibmax=5
+ if(nsym.eq.3) ibmax=8
+ do ib=0,ibmax
+ bm=maxval(s2(0:nt),one(0:nt,ibmax-ib)) - &
+ maxval(s2(0:nt),.not.one(0:nt,ibmax-ib))
+ if(i32+ib .gt.174) cycle
+ if(nsym.eq.1) then
+ bmeta(i32+ib)=bm
+ den=max(maxval(s2(0:nt),one(0:nt,ibmax-ib)), &
+ maxval(s2(0:nt),.not.one(0:nt,ibmax-ib)))
+ if(den.gt.0.0) then
+ cm=bm/den
+ else
+ cm=0.0
+ endif
+ bmetd(i32+ib)=cm
+ elseif(nsym.eq.2) then
+ bmetb(i32+ib)=bm
+ elseif(nsym.eq.3) then
+ bmetc(i32+ib)=bm
+ endif
+ enddo
+ enddo ! k
+ enddo ! ihalf
+ enddo ! nsym
+
+!tests
+!call indexx(bmetc(1:174),174,indx)
+!src=abs(bmetc(indx(1))/bmetc(indx(174)))
+!print *,src
+
+ call normalizebmetvar(bmeta,174)
+ call normalizebmetvar(bmetb,174)
+ call normalizebmetvar(bmetc,174)
+ call normalizebmetvar(bmetd,174)
+ scalefac=2.83
+ llra=scalefac*bmeta
+ llrb=scalefac*bmetb
+ llrc=scalefac*bmetc
+ llrd=scalefac*bmetd
+ apmag=maxval(abs(llra))*1.01
+
+! isubp2 #
+!------------------------------
+! 1 regular decoding, nsym=1
+! 2 regular decoding, nsym=2
+! 3 regular decoding, nsym=3
+! 4 regular decoding, llrd
+! 5..18 ap passes
+
+! iaptype Hound OFF, MyCall is standard, DXCall is standard or empty
+!------------------------
+! 0 cycle
+! 1 CQ ??? ??? (29+3=32 ap bits)
+! 2 MyCall ??? ??? (29+3=32 ap bits)
+! 3 MyCall DxCall ??? (58+3=61 ap bits)
+! 4 MyCall DxCall RRR (77 ap bits)
+! 5 MyCall DxCall 73 (77 ap bits)
+! 6 MyCall DxCall RR73 (77 ap bits)
+
+! naptypes(nQSOProgress, extra decoding pass)
+! 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
+! 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+! data naptypes(0,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx6 CQ
+! data naptypes(1,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx1 Grid
+! data naptypes(2,1:27)/3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx2 Report
+! data naptypes(3,1:27)/3,3,3,6,6,6,5,5,5,4,4,4,0,0,0,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx3 RRreport
+! data naptypes(4,1:27)/3,3,3,6,6,6,5,5,5,4,4,4,2,2,2,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx4 RRR,RR73
+! data naptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx5 73
+
+! iaptype standard DxCall tracking, also valid in Hound mode
+!------------------------
+! 31 CQ DxCall Grid(???) (77 ap bits)
+! 35 ??? DxCall 73 (29+19 ap bits)
+! 36 ??? DxCall RR73 (29+19 ap bits)
+
+! iaptype Hound off, MyCall is nonstandard, DXCall is standard or empty
+!------------------------
+! 0 cycle
+! 1 CQ ??? ??? (29+3=32 ap bits)
+! 40 <MyCall> ??? ??? (29+3=32 ap bits) incoming call
+! 41 <MyCall> DxCall ??? (58 ap bits) REPORT/RREPORT
+! 42 MyCall <DxCall> RRR (77 ap bits)
+! 43 MyCall <DxCall> 73 (77 ap bits)
+! 44 MyCall <DxCall> RR73 (77 ap bits)
+! 31 CQ DxCall Grid(???) (77 ap bits) standard DxCall tracking
+! 35 ??? DxCall 73 (29+19 ap bits) standard DxCall tracking
+! 36 ??? DxCall RR73 (29+19 ap bits) standard DxCall tracking
+
+! nmycnsaptypes(nQSOProgress, extra decoding pass)
+! data nmycnsaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,40,40,40,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx6 CQ
+! data nmycnsaptypes(1,1:27)/41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx1 DXcall MyCall
+! data nmycnsaptypes(2,1:27)/41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx2 Report
+! data nmycnsaptypes(3,1:27)/41,41,41,44,44,44,43,43,43,42,42,42,0,0,0,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx3 RRreport
+! data nmycnsaptypes(4,1:27)/41,41,41,44,44,44,43,43,43,42,42,42,40,40,40,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx4 RRR,RR73
+! data nmycnsaptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,40,40,40,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx5 73
+
+! iaptype Hound off, MyCall is standard, DXCall is not empty and is nonstandard
+!------------------------
+! 0 cycle
+! 1 CQ ??? ??? (29+3=32 ap bits)
+! 2 MyCall ??? ??? (29+3=32 ap bits)
+! 11 MyCall <DxCall> ??? (58 ap bits) REPORT/RREPORT
+! 12 <MyCall> DxCall RRR (77 ap bits)
+! 13 <MyCall> DxCall 73 (77 ap bits)
+! 14 <MyCall> DxCall RR73 (77 ap bits)
+! 31 CQ DxCall (77 ap bits) ! full compound or just nonstandard callsign
+! 35 ??? DxCall 73 (64 ap bits) ! full compound or just nonstandard callsign
+! 36 ??? DxCall RR73 (64 ap bits) ! full compound or just nonstandard callsign
+
+! ndxnsaptypes(nQSOProgress, extra decoding pass)
+! data ndxnsaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx6 CQ
+! data ndxnsaptypes(1,1:27)/11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx1 Grid
+! data ndxnsaptypes(2,1:27)/11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx2 Report
+! data ndxnsaptypes(3,1:27)/11,11,11,14,14,14,13,13,13,12,12,12,0,0,0,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx3 RRreport
+! data ndxnsaptypes(4,1:27)/11,11,11,14,14,14,13,13,13,12,12,12,2,2,2,0,0,0,31,31,31,36,36,36,35,35,35/ ! Tx4 RRR,RR73
+! data ndxnsaptypes(5,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1,1,1,31,31,31,36,36,36,35,35,35/ ! Tx5 73
+
+! iaptype Hound mode
+!------------------------
+! 0 cycle
+! 1 CQ ??? ??? (29+3=32 ap bits) standard callsign
+! 21 MyBaseCall DxBaseCall ??? (58+3=61 ap bits) Report
+! 22 ??? RR73; MyCall <???> ??? (28+6=34 ap bits)
+! 23 MyBaseCall DxBaseCall RR73 (77 ap bits)
+! 24 MyCall RR73; ??? <???> ??? (28+6=34 ap bits)
+! 31 CQ DxCall (DXGrid) (77 ap bits) ! standard/full compound or just nonstandard callsign
+! 36 ??? DxCall RR73 (29+19/64 ap bits) ! standard/ full compound or just nonstandard callsign
+! 111 CQ ??? (3 last i3 bits) type 4 message with nonstandard callsign
+
+! nhaptypes(nQSOProgress, extra decoding pass)
+! data nhaptypes(0,1:27)/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,111,111,111/ ! Tx6 CQ, possible in idle mode if DXCall is empty
+! data nhaptypes(1,1:27)/21,21,21,22,22,22,0,0,0,0,0,0,0,0,0,31,31,31,0,0,0,36,36,36,0,0,0/ ! Tx1 Grid idle mode or transmitting
+! data nhaptypes(2,1:27)/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,0/ ! Tx2 none
+! data nhaptypes(3,1:27)/21,21,21,22,22,22,23,23,23,24,24,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0/ ! Tx3 RRreport QSO in progress or QSO is finished
+! data nhaptypes(4,1:27)/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,0/ ! Tx4 none
+! data nhaptypes(5,1:27)/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,0/ ! Tx5 none
+
+ loutapwid=.false.
+ loutapwid=abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid
+ scqnr=2.
+ smycnr=2.
+
+ ! print*,'stophint is ',stophint,' lft8sdec is ',lft8sdec
+ ! print*,'lnohiscall is ',lnohiscall,' loutapwid is ',loutapwid
+ ! print*,'lenabledxcsearch ',lenabledxcsearch, ' lwidedxcsearch is ',lwidedxcsearch
+ ! print*,'lcqdxcsig is', lcqdxcsig
+ ! print*,'lcqsignal is',lcqsignal
+ ! print*,'ldxcsig',ldxcsig
+ ! print*,'lhiscallstd',lhiscallstd
+ ! print*,'mycall ',mycall,mybcall
+ ! print*,'hiscall ',hiscall,hisbcall
+ ! print*,'hisgrid is ',hisgrid
+
+ do isubp2=1,31
+ if(isubp2.lt.5) then
+ if(lapcqonly .or. lskipnotap) cycle
+ if(ltxing) then
+ ! enabled Tx and transmitted message including CQ at last interval
+ if(abs(f1-nfqso).lt.3.0) then ! +- 3Hz sync8var QSOfreq candidate list
+ if(syncavemax.lt.1.8) cycle
+ else
+ if(syncavemax.lt.1.9) cycle
+ endif
+ else
+ if(syncavemax.lt.1.8) cycle
+ endif
+ endif
+ if(isubp2.eq.4) cycle
+ if(isubp1.gt.2 .and. isubp2.lt.5) cycle ! skip regular decoding for extra subpasses
+ if(lqsocandave) then
+ if(isubp1.gt.2 .and. isubp1.lt.9) cycle ! skip other extra subpasses if QSO signal, highest priority
+ if(lqsomsgdcd) cycle
+ else if(lmycsignal .and. lmycallstd) then
+ if(isubp1.gt.2 .and. isubp1.lt.6) cycle ! skip CQ signal extra subpasses if MyCall signal
+ endif
+
+ if(isubp2.lt.5) then
+ apmask=0
+ iaptype2=iaptype
+ iaptype=0
+ if(isubp2.eq.1) then
+ if(ipass.eq.1) then
+ llrz=llrd
+ else
+ llrz=llra
+ endif
+ if(isubp1.gt.1 .and. ipass.gt.1) llrz=llrd
+ else if(isubp2.eq.2) then
+ llrz=llrb
+ if(isubp1.gt.1) llrz=llra
+ else if(isubp2.eq.3) then
+ llrz=llrc
+ else if(isubp2.eq.4) then
+ llrz=llrd
+ endif
+ else
+ if(.not.lhound) then
+ if(lmycallstd .and. (lhiscallstd .or. lnohiscall)) then
+ iaptype=naptypes(nQSOProgress,isubp2-4)
+ iaptype2=iaptype
+ ! print*,'line 1357 iaptype,isubp1,isubp2 = ',iaptype,isubp1,isubp2
+ if(iaptype.eq.0) cycle
+ if(lqsomsgdcd .and. iaptype.gt.2 .and. iaptype.lt.31) cycle ! QSO message already decoded
+ if(iaptype.eq.2) then
+ if(.not.lapmyc .or. lapcqonly) cycle ! skip AP for 'mycall ???? ????' in 2..3 minutes after last TX
+ if(nQSOProgress.ne.0 .and. nmic.lt.2) cycle ! reduce CPU load at QSO
+ endif
+ ! if(.not.stophint .and. iaptype.gt.30) cycle ! no DXCall searching at QSO, reduce Lag
+ ! if(stophint .and. iaptype.gt.2 .and. iaptype.lt.31) cycle
+ if(lft8sdec .and. iaptype.gt.2) cycle ! QSO message already decoded
+ if(iaptype.gt.2 .and. lnohiscall) cycle ! no DXCall
+ if(iaptype.gt.2 .and. iaptype.lt.31 .and. loutapwid) cycle
+ ! if(iaptype.eq.3 .and. .not.lqsosigtype3) cycle ! not QSO signal
+ ! if(iaptype.eq.4 .and. .not.lqsorrr) cycle ! not RRR signal
+ ! if(iaptype.eq.5 .and. .not.lqso73) cycle ! not 73 signal
+ ! if(iaptype.eq.6 .and. .not.lqsorr73) cycle ! not RR73 signal
+ if(iaptype.gt.30 .and. .not.lenabledxcsearch) cycle ! in QSO or TXing CQ or last logged is DX Call: searching disabled
+ if(iaptype.gt.30 .and. .not.lwidedxcsearch .and. loutapwid) cycle ! only RX freq DX Call searching
+ if(iaptype.eq.31 .and. .not.lcqdxcsig) cycle ! not CQ signal from std DXCall
+ if(iaptype.eq.31 .and. .not.lhiscallstd .and. lapcqonly) cycle ! skip weak CQ signals with std call
+ if(iaptype.gt.31 .and. lapcqonly) cycle ! skip weak CQ signals
+ if(iaptype.eq.35 .and. .not.lqso73) cycle ! DXCall searching, not 73 signal
+ if(iaptype.eq.36 .and. .not.lqsorr73) cycle ! DXCall searching, not RR73 signal
+ if(lqsocandave .and. isubp1.gt.8 .and. (iaptype.lt.3 .or. iaptype.gt.6)) cycle ! QSO signal
+ ! if(.not.lqsocandave .and. lmycsignal .and. isubp1.gt.5 .and. isubp1.lt.9 .and. iaptype.ne.2) cycle ! skip other AP if lmycsignal extra subpasses)
+
+ if(iaptype.eq.1) then
+ if(isubp2.eq.20) then
+ scqlev=0.
+ do i4=1,9
+ scqlev=scqlev+s8(idtone25(2,i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-scqlev)/7.0
+ scqnr=scqlev/snoiselev
+ if(scqnr.lt.1.0 .and. .not.lcqsignal) cycle
+ endif
+ if(isubp2.eq.21) then
+ if(lft8lowth .or. lft8subpass) then
+ if(scqnr.lt.1.2 .and. .not.lcqsignal) cycle
+ endif
+ if(.not. lft8subpass .and. .not.lft8lowth) then
+ if(scqnr.lt.1.3 .and. .not.lcqsignal) cycle
+ endif
+ endif
+ endif
+
+ if(iaptype.eq.2) then
+ if(isubp2.eq.17) then
+ smyclev=0.
+ do i4=1,9
+ smyclev=smyclev+s8(idtonemyc(i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-smyclev)/7.0
+ smycnr=smyclev/snoiselev
+ if(smycnr.lt.1.0 .and. .not.lmycsignal) cycle
+ endif
+ if(isubp2.eq.18) then
+ if(lft8lowth .or. lft8subpass) then
+ if(smycnr.lt.1.2 .and. .not.lmycsignal) cycle
+ endif
+ endif
+ endif
+
+ if(iaptype.eq.3) then
+ if(isubp2.eq.5) then
+ smyclev=0.
+ do i4=1,9
+ smyclev=smyclev+s8(idtonemyc(i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-smyclev)/7.0
+ smycnr=smyclev/snoiselev
+ if(smycnr.lt.1.0) cycle
+ else if(isubp2.eq.6) then
+ if(smycnr.lt.1.2) cycle
+ endif
+ endif
+
+ apmask=0
+ if(iaptype.eq.1) then ! CQ
+ if(isubp2.eq.20) then
+ llrz=llrc
+ else if(isubp2.eq.21) then
+ llrz=llrb
+ else if(isubp2.eq.22) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.2) then ! MyCall ??? ???
+ if(isubp2.eq.17) then
+ llrz=llrc
+ else if(isubp2.eq.18) then
+ llrz=llrb
+ else if(isubp2.eq.19) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*apsym(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.3) then ! MyCall DxCall ???
+ if(isubp2.eq.5) then
+ llrz=llrc
+ else if(isubp2.eq.6) then
+ llrz=llrb
+ else if(isubp2.eq.7) then
+ llrz=llra
+ endif
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apsym
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.gt.3 .and. iaptype.lt.7) then
+ if(isubp2.eq.8 .or. isubp2.eq.11 .or. isubp2.eq.14) then
+ llrz=llrc
+ else if(isubp2.eq.9 .or. isubp2.eq.12 .or. isubp2.eq.15) then
+ llrz=llrb
+ else if(isubp2.eq.10 .or. isubp2.eq.13 .or. isubp2.eq.16) then
+ llrz=llrb
+ endif
+ apmask(1:77)=1
+ llrz(1:58)=apmag*apsym ! mycall hiscall 73|RR73
+ if(iaptype.eq.5) then
+ llrz(59:77)=apmag*m73
+ else if(iaptype.eq.6) then
+ llrz(59:77)=apmag*mrr73
+ else if(iaptype.eq.4) then
+ llrz(59:77)=apmag*mrrr
+ endif
+ else if(iaptype.eq.31) then ! CQ DxCall Grid(???)
+ if(isubp2.eq.23) then
+ llrz=llrc
+ else if(isubp2.eq.24) then
+ llrz=llrb
+ else if(isubp2.eq.25) then
+ llrz=llra
+ endif
+ if(lnohisgrid) then
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apcqsym(1:58)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ endif
+ else if(iaptype.eq.35) then ! ??? DxCall 73, type 1 std DXCall
+ if(isubp2.eq.29) then
+ llrz=llrc
+ else if(isubp2.eq.30) then
+ llrz=llrb
+ else if(isubp2.eq.31) then
+ llrz=llra
+ endif
+ apmask(30:77)=1
+ llrz(30:58)=apmag*apsym(30:58)
+ llrz(59:77)=apmag*m73
+ else if(iaptype.eq.36) then ! ??? DxCall RR73 type 1 std DXCall
+ if(isubp2.eq.26) then
+ llrz=llrc
+ else if(isubp2.eq.27) then
+ llrz=llrb
+ else if(isubp2.eq.28) then
+ llrz=llra
+ endif
+ apmask(30:77)=1
+ llrz(30:58)=apmag*apsym(30:58)
+ llrz(59:77)=apmag*mrr73
+ endif
+
+ !! print*,'line 1533 iaptype,isubp1,isubp2 = ',iaptype,isubp1,isubp2
+
+ else if(lmycallstd .and. .not.lhiscallstd .and. &
+ len_trim(hiscall).gt.2) then
+ iaptype=ndxnsaptypes(nQSOProgress,isubp2-4)
+ iaptype2=iaptype
+ if(iaptype.eq.0) cycle
+ if(iaptype.eq.2 .and. lapcqonly) cycle ! skip weak CQ signals
+ if(.not.stophint .and. iaptype.gt.30) cycle ! no DXCall searching at QSO, reduce Lag
+ if((lqsomsgdcd .or. .not.lapmyc) .and. iaptype.gt.1 .and. iaptype.lt.15) cycle ! skip AP for mycall in 2..3 minutes after last TX
+ if(iaptype.eq.12 .and. .not.lqsorrr) cycle ! not RRR signal
+ if(iaptype.eq.13 .and. .not.lqso73) cycle ! not 73 signal
+ if(iaptype.eq.14 .and. .not.lqsorr73) cycle ! not RR73 signal
+ if(iaptype.gt.30 .and. .not.lenabledxcsearch) cycle ! in QSO or TXing CQ or last logged is DX Call: searching disabled
+ if(iaptype.gt.30 .and. .not.lwidedxcsearch .and. loutapwid) cycle ! only RX freq DX Call searching
+ if(iaptype.gt.30 .and. lapcqonly) cycle ! skip weak CQ signals
+ if(iaptype.eq.31 .and. .not.lcqdxcnssig) cycle ! it is not CQ signal of non-standard DXCall
+ if(iaptype.eq.35 .and. .not.lqso73) cycle ! DXCall searching, not 73 signal
+ if(iaptype.eq.36 .and. .not.lqsorr73) cycle ! DXCall searching, not RR73 signal
+ if(lqsocandave .and. isubp1.gt.8 .and. (iaptype.lt.11 .or. iaptype.gt.14)) cycle ! QSO signal
+ if(iaptype.gt.2 .and. iaptype.lt.15 .and. loutapwid) cycle
+
+ if(iaptype.eq.1) then
+ if(isubp2.eq.20) then
+ scqlev=0.
+ do i4=1,9
+ scqlev=scqlev+s8(idtone25(2,i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-scqlev)/7.0
+ scqnr=scqlev/snoiselev
+ if(scqnr.lt.1.0 .and. .not.lcqsignal) cycle
+ endif
+ if(isubp2.eq.21) then
+ if(lft8lowth .or. lft8subpass) then
+ if(scqnr.lt.1.2 .and. .not.lcqsignal) cycle
+ endif
+ if(.not. lft8subpass .and. .not.lft8lowth) then
+ if(scqnr.lt.1.3 .and. .not.lcqsignal) cycle
+ endif
+ endif
+ endif
+
+ if(iaptype.eq.2) then
+ if(isubp2.eq.17) then
+ smyclev=0.
+ do i4=1,9
+ smyclev=smyclev+s8(idtonemyc(i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-smyclev)/7.0
+ smycnr=smyclev/snoiselev
+ if(smycnr.lt.1.0 .and. .not.lmycsignal) cycle
+ endif
+ if(isubp2.eq.18) then
+ if(lft8lowth .or. lft8subpass) then
+ if(smycnr.lt.1.2 .and. .not.lmycsignal) cycle
+ endif
+ endif
+ endif
+
+ apmask=0
+ if(iaptype.eq.1) then ! CQ ??? ???
+ if(isubp2.eq.20) then
+ llrz=llrc
+ else if(isubp2.eq.21) then
+ llrz=llrb
+ else if(isubp2.eq.22) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.2) then ! MyCall ??? ???
+ if(isubp2.eq.17) then
+ llrz=llrc
+ else if(isubp2.eq.18) then
+ llrz=llrb
+ else if(isubp2.eq.19) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*apsym(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.11) then ! MyCall <DxCall> ??? ! report rreport type 1 msg
+ if(isubp2.eq.5) then
+ llrz=llrc
+ else if(isubp2.eq.6) then
+ llrz=llrb
+ else if(isubp2.eq.7) then
+ llrz=llra
+ endif
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apsymdxns1
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.12) then ! type 4 <MyCall> DxCall RRR
+ if(isubp2.eq.14) then
+ llrz=llrc
+ else if(isubp2.eq.15) then
+ llrz=llrb
+ else if(isubp2.eq.16) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymdxnsrrr
+ else if(iaptype.eq.13) then ! type 4 <MyCall> DxCall 73
+ if(isubp2.eq.11) then
+ llrz=llrc
+ else if(isubp2.eq.12) then
+ llrz=llrb
+ else if(isubp2.eq.13) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymdxns732
+ else if(iaptype.eq.14) then ! type 4 <MyCall> DxCall RR73
+ if(isubp2.eq.8) then
+ llrz=llrc
+ else if(isubp2.eq.9) then
+ llrz=llrb
+ else if(isubp2.eq.10) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymdxnsr73
+ else if(iaptype.eq.31) then ! CQ DxCall ! full compound or nonstandard
+ if(isubp2.eq.23) then
+ llrz=llrc
+ else if(isubp2.eq.24) then
+ llrz=llrb
+ else if(isubp2.eq.25) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ else if(iaptype.eq.35) then ! ??? DxCall 73 ! full compound or nonstandard
+ if(isubp2.eq.29) then
+ llrz=llrc
+ else if(isubp2.eq.30) then
+ llrz=llrb
+ else if(isubp2.eq.31) then
+ llrz=llra
+ endif
+ apmask(14:77)=1
+ llrz(14:77)=apmag*apsymdxns73(14:77)
+ else if(iaptype.eq.36) then ! ??? DxCall RR73 ! full compound or nonstandard
+ if(isubp2.eq.26) then
+ llrz=llrc
+ else if(isubp2.eq.27) then
+ llrz=llrb
+ else if(isubp2.eq.28) then
+ llrz=llra
+ endif
+ apmask(14:77)=1
+ llrz(14:77)=apmag*apsymdxnsrr73(14:77)
+ endif
+
+ else if(.not.lmycallstd .and. .not.lhiscallstd .and. &
+ len_trim(hiscall).gt.2) then ! empty mycall or compound/nonstandard both calls
+ iaptype=ndxnsaptypes(nQSOProgress,isubp2-4)
+ iaptype2=iaptype
+ if(iaptype.eq.0) cycle
+ if(iaptype.gt.1 .and. iaptype.lt.31) cycle
+ if(.not.stophint .and. iaptype.gt.1) cycle ! on air, QSO is not possible
+ if(iaptype.gt.30 .and. lapcqonly) cycle ! skip weak CQ signals with std call
+ if(iaptype.eq.31 .and. .not.lcqdxcnssig) cycle ! it is not CQ signal of non-standard DXCall
+ if(iaptype.gt.34 .and. .not.ldxcsig) cycle ! not DXCall signal
+
+ if(iaptype.eq.1) then
+ if(isubp2.eq.20) then
+ scqlev=0.
+ do i4=1,9
+ scqlev=scqlev+s8(idtone25(2,i4),i4+7)
+ enddo
+ snoiselev=(sum(s8(0:7,8:16))-scqlev)/7.0
+ scqnr=scqlev/snoiselev
+ if(scqnr.lt.1.0 .and. .not.lcqsignal) cycle
+ endif
+ if(isubp2.eq.21) then
+ if(lft8lowth .or. lft8subpass)then
+ if(scqnr.lt.1.2 .and. .not.lcqsignal) cycle
+ endif
+ if(.not. lft8subpass .and. .not.lft8lowth) then
+ if(scqnr.lt.1.3 .and. .not.lcqsignal) cycle
+ endif
+ endif
+ endif
+
+ apmask=0
+ if(iaptype.eq.1) then ! CQ ??? ???
+ if(isubp2.eq.20) then
+ llrz=llrc
+ else if(isubp2.eq.21) then
+ llrz=llrb
+ else if(isubp2.eq.22) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+
+! Nonstandard DXCall search masks below are for monitoring purpose in idle mode,
+! QSO is not possible
+! wideband searching being used by default
+
+ else if(iaptype.eq.31) then ! CQ DxCall ! full compound or nonstandard
+ if(isubp2.eq.23) then
+ llrz=llrc
+ else if(isubp2.eq.24) then
+ llrz=llrb
+ else if(isubp2.eq.25) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ else if(iaptype.eq.35) then ! ??? DxCall 73 ! full compound or nonstandard
+ if(isubp2.eq.29) then
+ llrz=llrc
+ else if(isubp2.eq.30) then
+ llrz=llrb
+ else if(isubp2.eq.31) then
+ llrz=llra
+ endif
+ apmask(14:77)=1
+ llrz(14:77)=apmag*apsymdxns73(14:77)
+ else if(iaptype.eq.36) then ! ??? DxCall RR73 ! full compound or nonstandard
+ if(isubp2.eq.26) then
+ llrz=llrc
+ else if(isubp2.eq.27) then
+ llrz=llrb
+ else if(isubp2.eq.28) then
+ llrz=llra
+ endif
+ apmask(14:77)=1
+ llrz(14:77)=apmag*apsymdxnsrr73(14:77)
+ endif
+
+ else if(.not.lmycallstd .and. (lhiscallstd .or. lnohiscall)) then
+ iaptype=nmycnsaptypes(nQSOProgress,isubp2-4)
+ iaptype2=iaptype
+ if(iaptype.eq.0) cycle
+ if(isubp1.eq.2 .and. nweak.eq.1) cycle
+ if(isubp1.gt.5) cycle ! so far CQ averaging only
+ if(iaptype.eq.40 .and. lapcqonly) cycle ! skip weak CQ signals
+ if(iaptype.gt.40 .and. iaptype.lt.45 .and. lqsomsgdcd) cycle ! already decoded
+ if(iaptype.eq.42 .and. .not.lqsorrr) cycle ! not RRR signal
+ if(iaptype.eq.43 .and. .not.lqso73) cycle ! not 73 signal
+ if(iaptype.eq.44 .and. .not.lqsorr73) cycle ! not RR73 signal
+ if(iaptype.gt.39 .and. .not.lapmyc) cycle
+ if(lnomycall .and. iaptype.gt.39 .and. iaptype.lt.45) cycle ! skip QSO signals if mycall is empty
+ if(lnohiscall .and. iaptype.ne.1 .and. iaptype.ne.40) cycle ! skip DXCall masks if empty
+ if(iaptype.gt.30 .and. iaptype.lt.40 .and. .not.stophint) cycle ! in QSO, reduce number of CPU cycles
+ if(iaptype.eq.31 .and. .not.lcqdxcsig) cycle ! not CQ signal from std DXCall
+ if(iaptype.gt.34 .and. iaptype.lt.37 .and. (.not.ldxcsig .or. lapcqonly)) cycle ! not DXCall signal, skip weak CQ signals
+ if(iaptype.gt.30 .and. iaptype.lt.40 .and. .not.lwidedxcsearch .and. loutapwid) cycle ! if wideband DX search disabled
+
+ apmask=0
+ if(lcqsignal .and. iaptype.eq.1) then ! CQ ??? ???
+ if(isubp2.eq.20) then
+ llrz=llrc
+ else if(isubp2.eq.21) then
+ llrz=llrb
+ else if(isubp2.eq.22) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.31) then ! CQ DxCall Grid(???) //std DX call type1 with or without grid
+ if(isubp2.eq.23) then
+ llrz=llrc
+ else if(isubp2.eq.24) then
+ llrz=llrb
+ else if(isubp2.eq.25) then
+ llrz=llra
+ endif
+ if(lnohisgrid) then
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apcqsym(1:58)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ endif
+ else if(iaptype.eq.35) then ! ??? DxCall 73 //std DX call
+ if(isubp2.eq.29) then
+ llrz=llrc
+ else if(isubp2.eq.30) then
+ llrz=llrb
+ else if(isubp2.eq.31) then
+ llrz=llra
+ endif
+ apmask(30:77)=1
+ llrz(30:58)=apmag*apsymdxstd(30:58)
+ llrz(59:77)=apmag*m73
+ else if(iaptype.eq.36) then ! ??? DxCall RR73 //std DX call
+ if(isubp2.eq.26) then
+ llrz=llrc
+ else if(isubp2.eq.27) then
+ llrz=llrb
+ else if(isubp2.eq.28) then
+ llrz=llra
+ endif
+ apmask(30:77)=1
+ llrz(30:58)=apmag*apsymdxstd(30:58)
+ llrz(59:77)=apmag*mrr73
+ else if(iaptype.eq.40) then ! <MyCall>,???,??? type 1
+ if(isubp2.eq.17) then
+ llrz=llrc
+ else if(isubp2.eq.18) then
+ llrz=llrb
+ else if(isubp2.eq.19) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*apsymmyns1(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.41) then ! <MyCall>,DXCall,??? type 1
+ if(isubp2.eq.5) then
+ llrz=llrc
+ else if(isubp2.eq.6) then
+ llrz=llrb
+ else if(isubp2.eq.7) then
+ llrz=llra
+ endif
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apsymmyns2
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.42) then ! MyCall,<DXCall>,RRR type 4
+ if(isubp2.eq.14) then
+ llrz=llrc
+ else if(isubp2.eq.15) then
+ llrz=llrb
+ else if(isubp2.eq.16) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymmynsrrr
+ else if(iaptype.eq.43) then ! MyCall,<DXCall>,73 type 4
+ if(isubp2.eq.11) then
+ llrz=llrc
+ else if(isubp2.eq.12) then
+ llrz=llrb
+ else if(isubp2.eq.13) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymmyns73
+ else if(iaptype.eq.44) then ! MyCall,<DXCall>,RR73 type 4
+ if(isubp2.eq.8) then
+ llrz=llrc
+ else if(isubp2.eq.9) then
+ llrz=llrb
+ else if(isubp2.eq.10) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apsymmynsrr73
+ endif
+ else
+ cycle ! fallback
+ endif
+
+ else if(lhound) then
+ iaptype=nhaptypes(nQSOProgress,isubp2-4)
+ iaptype2=iaptype
+ if(iaptype.eq.0) cycle
+ if(lnomycall .and. iaptype.gt.1 .and. iaptype.lt.31) cycle ! skip AP if mycall is missed in config
+ if(lhiscallstd .and. iaptype.eq.31 .and. .not.lcqsignal) cycle ! not CQ signal, skip CQ DXCall DXgrid mask
+ if(lqsomsgdcd .and. iaptype.gt.0 .and. iaptype.lt.25) cycle ! QSO message already decoded
+ if(.not.stophint .and. (iaptype.eq.31 .or. iaptype.eq.36)) cycle ! CQ and RR73 decoding not needed if TX is on
+ if(nQSOProgress.eq.1) then
+ if(lfoxspecrpt) then
+ if(iaptype.eq.21) cycle ! it is not standard message report signal
+ if((iaptype.eq.31 .or. iaptype.eq.36) .and. nfoxspecrpt.gt.3) cycle ! probably special message signal
+ else
+ if(iaptype.eq.22) cycle ! it is not special message report signal
+ if((iaptype.eq.31 .or. iaptype.eq.36) .and. nmic.gt.3) cycle ! probably standard message signal with mybcall
+ endif
+ endif
+ if(nQSOProgress.eq.3) then
+ if(lfoxspecrpt) then
+ if(iaptype.eq.21) cycle ! it is not standard message report signal
+ else
+ if(iaptype.eq.22) cycle ! it is not special message report signal
+ endif
+ if(lfoxstdr73) then
+ if(iaptype.eq.24) cycle ! it is not special message RR73 signal
+ else
+ if(iaptype.eq.23) cycle ! it is not standard message RR73 signal
+ endif
+ endif
+! can be staying in queue, need to process possible incoming report iaptype 21/22 even if TX is switched off
+ if(.not.lapmyc .and. (iaptype.eq.23 .or. iaptype.eq.24)) cycle ! skip AP for mycall RR73 in 2..3 minutes after last TX
+ fdelta=abs(f1-nfqso)
+ fdeltam=modulo(fdelta,60.) ! dupe string to prevent compiler warning
+ if(nQSOProgress.gt.0 .and. iaptype.lt.31 .and. (fdelta.gt.245.0 .or. &
+ fdeltam.gt.3.0)) cycle ! AP shall be applied to Fox frequencies only
+ if((iaptype.eq.31 .or. iaptype.eq.36) .and. .not.lwidedxcsearch .and. &
+ (fdelta.gt.245.0 .or. fdeltam.gt.3.0)) cycle ! only Fox frequencies DX Call searching
+ if(iaptype.eq.31 .and. .not.lhiscallstd .and. lapcqonly) cycle ! skip weak CQ signals with std call
+ if(iaptype.eq.36 .and. lwidedxcsearch .and. lapcqonly) cycle ! skip weak CQ signals
+ if(iaptype.eq.111 .and. lapcqonly) cycle ! skip weak CQ signals with std call
+
+ apmask=0
+ if(iaptype.eq.1) then ! CQ ??? ??? type 1 msg
+ if(isubp2.eq.20) then
+ llrz=llrc
+ else if(isubp2.eq.21) then
+ llrz=llrb
+ else if(isubp2.eq.22) then
+ llrz=llra
+ endif
+ apmask(1:29)=1
+ llrz(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.21) then ! MyBaseCall DxBaseCall ??? ! report
+ if(isubp2.eq.5) then
+ llrz=llrc
+ else if(isubp2.eq.6) then
+ llrz=llrb
+ else if(isubp2.eq.7) then
+ llrz=llra
+ endif
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apsym
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else if(iaptype.eq.22) then ! ??? RR73; MyCall <???> ??? ! report
+ if(isubp2.eq.8) then
+ llrz=llrc
+ else if(isubp2.eq.9) then
+ llrz=llrb
+ else if(isubp2.eq.10) then
+ llrz=llra
+ endif
+ apmask(29:66)=1
+ llrz(29:66)=apmag*apsymsp(29:66)
+ apmask(72:77)=1
+ llrz(72:73)=apmag*(-1)
+ llrz(74)=apmag*(+1)
+ llrz(75:77)=apmag*(-1)
+ else if(iaptype.eq.23) then ! MyBaseCall DxBaseCall RR73
+ if(isubp2.eq.11) then
+ llrz=llrc
+ else if(isubp2.eq.12) then
+ llrz=llrb
+ else if(isubp2.eq.13) then
+ llrz=llra
+ endif
+ apmask(1:77)=1
+ llrz(1:58)=apmag*apsym
+ llrz(59:77)=apmag*mrr73
+ else if(iaptype.eq.24) then ! MyCall RR73; ??? <???> ???
+ if(isubp2.eq.14) then
+ llrz=llrc
+ else if(isubp2.eq.15) then
+ llrz=llrb
+ else if(isubp2.eq.16) then
+ llrz=llra
+ endif
+ apmask(1:28)=1
+ apmask(57:66)=1
+ llrz(1:28)=apmag*apsymsp(1:28)
+ llrz(57:66)=apmag*apsymsp(57:66)
+ apmask(72:77)=1
+ llrz(72:73)=apmag*(-1)
+ llrz(74)=apmag*(+1)
+ llrz(75:77)=apmag*(-1)
+ else if(iaptype.eq.31) then ! CQ DxCall Grid(???)
+ if(isubp2.eq.23) then
+ llrz=llrc
+ else if(isubp2.eq.24) then
+ llrz=llrb
+ else if(isubp2.eq.25) then
+ llrz=llra
+ endif
+ if(lhiscallstd) then
+ if(lnohisgrid) then
+ apmask(1:58)=1
+ llrz(1:58)=apmag*apcqsym(1:58)
+ apmask(75:77)=1
+ llrz(75:76)=apmag*(-1)
+ llrz(77)=apmag*(+1)
+ else
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ endif
+ else
+ apmask(1:77)=1
+ llrz(1:77)=apmag*apcqsym
+ endif
+ else if(iaptype.eq.36) then
+ if(isubp2.eq.26) then
+ llrz=llrc
+ else if(isubp2.eq.27) then
+ llrz=llrb
+ else if(isubp2.eq.28) then
+ llrz=llra
+ endif
+ if(lhiscallstd .or. (.not.lhiscallstd .and. &
+ len_trim(hiscall).gt.2 &
+ .and. index(hiscall,"/").gt.0)) then
+ apmask(30:77)=1
+ llrz(30:58)=apmag*apsym(30:58)
+ llrz(59:77)=apmag*mrr73 ! ??? DxBaseCall RR73
+ else
+ cycle ! (noncompound .and. nonstandard) Fox callsign being not supported by Fox WSJT-X
+ endif
+ else if(iaptype.eq.111) then ! CQ ??? type 4 msg (iflip,nrpt,icq,i3 001100)
+ if(isubp2.eq.29) then
+ llrz=llrc
+ else if(isubp2.eq.30) then
+ llrz=llrb
+ else if(isubp2.eq.31) then
+ llrz=llra
+ endif
+ apmask(72:77)=1
+ llrz(72:73)=apmag*(-1)
+ llrz(74:75)=apmag*(1)
+ llrz(76:77)=apmag*(-1)
+ endif
+ else
+ cycle ! fallback
+ endif
+ endif
+ cw=0
+ call bpdecode174_91var(llrz,apmask,max_iterations,message77,cw, &
+ nharderrors,niterations)
+ dmin=0.0
+ if(nharderrors.lt.0) then
+ ndeep=3
+ if(lqsosig .or. lmycsignal) then
+ if((dfqso.lt.napwid .or. (abs(nftx-f1).lt.napwid .and. lapmyc)) &
+ .and. .not.nagainfil) ndeep=4
+ if(lapmyc .and. lqsomsgdcd .or. iaptype.eq.0) ndeep=3 ! deep is not needed, reduce number of CPU cycles
+ if(.not.stophint .and. len_trim(hiscall).gt.2) ndeep=3 ! unload CPU, let ft8svar pick up QSO message
+ endif
+ if(ldxcsig .and. stophint .and. dfqso.lt.napwid) ndeep=4 ! DXCall search inside RX napwid
+ if(lhound) ndeep=3 ! we have no enough CPU resources to decode all Fox slots with ndeep=4
+! if(nagainfil .or. swl) ndeep=5 ! 30 against 26 -23dB, more than 15sec to decode and many false decodes
+! if(swl) ndeep=4 ! 29 decodes -23dB, 7..12sec to decode
+ if(nagainfil) ndeep=5
+!print *,omp_get_nested(),OMP_get_num_threads()
+
+ call osd174_91var(llrz,apmask,ndeep,message77,cw,nharderrors,dmin,nthr)
+ endif
+
+ nbadcrc=1
+ msg37=''
+ if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword
+ if(nharderrors.lt.0 .or. nharderrors+dmin.ge.60.0 .or. (isubp2.gt.2 &
+ .and. nharderrors.gt.39)) then ! chk isubp2 value
+ if(nweak.eq.2 .and. isubp1.eq.2) then
+ if(ipass.eq.npass-1) then
+ if(lcqsignal) then
+ if(isubp2.eq.22) then ! last pass, std and nonstd mycall
+ lfoundcq=.false.
+ do ik=1,numdeccq
+ if(tmpcqdec(ik)%freq.gt.5001.0) exit
+ if(abs(tmpcqdec(ik)%freq-f1).lt.5.0 .and. abs(tmpcqdec(ik)%xdt-xdt).lt.0.05) then ! max signal delay
+ lfoundcq=.true.
+ exit
+ endif
+ enddo
+ if(.not.lfoundcq .and. ncqsignal.lt.numcqsig) then
+ ncqsignal=ncqsignal+1
+ tmpcqsig(ncqsignal)%freq=f1
+ tmpcqsig(ncqsignal)%xdt=xdt
+ tmpcqsig(ncqsignal)%cs=cstmp2
+ endif
+ endif
+ endif
+ if(lmycsignal .and. isubp2.eq.19) then ! last pass
+ lfoundmyc=.false.
+ do ik=1,numdecmyc
+ if(tmpmyc(ik)%freq.gt.5001.0) exit
+ if(abs(tmpmyc(ik)%freq-f1).lt.5.0 .and. &
+ abs(tmpmyc(ik)%xdt-xdt).lt.0.05) then ! max signal delay
+ lfoundmyc=.true.
+ exit
+ endif
+ enddo
+ if(.not.lfoundmyc .and. nmycsignal.lt.nummycsig) then
+ nmycsignal=nmycsignal+1
+ tmpmycsig(nmycsignal)%freq=f1
+ tmpmycsig(nmycsignal)%xdt=xdt
+ tmpmycsig(nmycsignal)%cs=cstmp2
+ endif
+ endif
+ endif
+ if(ipass.eq.npass) then
+ if(lqsocandave .and. (iaptype.eq.3 .or. iaptype.eq.6)) then
+ tmpqsosig(1)%freq=f1
+ tmpqsosig(1)%xdt=xdt
+ tmpqsosig(1)%cs=cstmp2
+ endif
+ endif
+ endif
+ !print*,'line 2149 iaptype,isubp1,isubp2,ndeep = ',iaptype,isubp1,isubp2,ndeep
+
+ if(isubp1.gt.1) cycle
+ ! print*,'line 2150 did not cycle'
+ if(lqsothread .and. (.not.lhound .and. iaptype.ge.3 .or. lhound &
+ .and. (iaptype.eq.21 .or. iaptype.eq.23)) .and. .not.lsdone) then
+ if(.not.lqsomsgdcd .and. .not.(.not.lmycallstd .and. &
+ .not.lhiscallstd)) then
+ if(.not.lft8sdec .and. .not.stophint .and. dfqso.lt.2.0) then
+ call ft8svar(s8,srr,itone,msg37,lft8s,nft8rxfsens,stophint)
+ if(lft8s) then
+ if(index(msg37,'<').gt.0) then
+ lhashmsg=.true.
+ endif
+ nbadcrc=0
+ lft8sdec=.true.
+ endif
+ endif
+ endif
+ lsdone=.true.
+ endif
+ if(nbadcrc.eq.0) then
+ i3=1
+ n3=1
+ exit
+ endif
+
+ if(lsd .and. isubp2.eq.3 .and. nbadcrc.eq.1 .and. srr.lt.7.0) then ! low DR setups shall not try FT8SDvar for strong signals
+ call ft8sdvar(s8,srr,itone,msgd,msg37,lft8sd,lcq)
+ if(lft8sd) then
+ if(levenint) then
+ evencopy(isd)%lstate=.false.
+ elseif(loddint) then
+ oddcopy(isd)%lstate=.false.
+ endif
+ i3=1
+ n3=1
+ iaptype2=iaptype
+ iaptype=0
+ nbadcrc=0
+ lsd=.false.
+ exit
+ endif
+ endif
+
+ if(nweak.eq.1 .and. isubp1.eq.1) then
+ if(ipass.eq.npass-1) then
+ if(lcqsignal) then
+ if(isubp2.eq.22) then ! last pass, std and nonstd mycall
+ lfoundcq=.false.
+ do ik=1,numdeccq
+ if(tmpcqdec(ik)%freq.gt.5001.0) exit
+ if(abs(tmpcqdec(ik)%freq-f1).lt.5.0 .and. &
+ abs(tmpcqdec(ik)%xdt-xdt).lt.0.05) then ! max signal delay
+ lfoundcq=.true.
+ exit
+ endif
+ enddo
+ if(.not.lfoundcq .and. ncqsignal.lt.numcqsig) then
+ ncqsignal=ncqsignal+1
+ tmpcqsig(ncqsignal)%freq=f1
+ tmpcqsig(ncqsignal)%xdt=xdt
+ tmpcqsig(ncqsignal)%cs=cstmp2
+ endif
+ endif
+ endif
+ if(lmycsignal .and. isubp2.eq.19) then ! last pass
+ lfoundmyc=.false.
+ do ik=1,numdecmyc
+ if(tmpmyc(ik)%freq.gt.5001.0) exit
+ if(abs(tmpmyc(ik)%freq-f1).lt.5.0 .and. &
+ abs(tmpmyc(ik)%xdt-xdt).lt.0.05) then ! max signal delay
+ lfoundmyc=.true.
+ exit
+ endif
+ enddo
+ if(.not.lfoundmyc .and. nmycsignal.lt.nummycsig) then
+ nmycsignal=nmycsignal+1
+ tmpmycsig(nmycsignal)%freq=f1
+ tmpmycsig(nmycsignal)%xdt=xdt
+ tmpmycsig(nmycsignal)%cs=cstmp2
+ endif
+ endif
+ endif
+ if(ipass.eq.npass) then
+ if(lqsocandave .and. (iaptype.eq.3 .or. iaptype.eq.6)) then
+ tmpqsosig(1)%freq=f1
+ tmpqsosig(1)%xdt=xdt
+ tmpqsosig(1)%cs=cstmp2
+ endif
+ endif
+ endif
+ ! print*,'line 2242 nbadcrc=',nbadcrc
+
+ if(nbadcrc.eq.1) cycle
+ endif
+
+ write(c77,'(77i1)') message77
+ read(c77(72:74),'(b3)') n3
+ read(c77(75:77),'(b3)') i3
+ !print*,'line 2247 iaptype=',iaptype,' i3=',i3,' n3=',n3
+ if((i3.gt.4 .or. (i3.eq.0 .and. n3.gt.5)) .and. (.not.(i3.eq.5 .and. &
+ (n3.eq.1 .or. n3.eq.7 .or.n3.eq.6 .or.n3.eq.4 .or.n3.eq.3 .or.n3.eq.0 .or.n3.eq.5)))) cycle ! ft8md added n3.eq.6 and n3.eq.4 and n3.eq.3 and n3.eq.0 and n3.eq.5 for USA calls with EU VHF
+ !print*,'did not cycle at line 2248'
+ call unpack77var(c77,1,msg37,unpk77_success,nthr)
+ if(.not.unpk77_success) then
+ if(lqsothread .and. (.not.lhound .and. iaptype.ge.3 .or. lhound .and. &
+ (iaptype.eq.21 .or. iaptype.eq.23)) .and. .not.lsdone) then
+ if(.not.lqsomsgdcd .and. .not.(.not.lmycallstd .and. &
+ .not.lhiscallstd)) then
+ if(.not.lft8sdec .and. .not.stophint .and. dfqso.lt.2.0) then
+ call ft8svar(s8,srr,itone,msg37,lft8s,nft8rxfsens,stophint)
+ if(lft8s) then
+ if(index(msg37,'<').gt.0) then
+ lhashmsg=.true.
+ endif
+ nbadcrc=0
+ lft8sdec=.true.
+ endif
+ endif
+ endif
+ lsdone=.true.
+ if(nbadcrc.eq.0) then
+ i3=1
+ n3=1
+ exit
+ endif
+ endif
+ cycle
+ endif
+
+ if(iaptype.eq.1 .and. msg37(1:10).eq.'CQ DE AA00') then
+ nbadcrc=1
+ cycle
+ endif
+ lcall1hash=.false.
+ if(msg37(1:1).eq.'<') lcall1hash=.true.
+ nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message.
+ call get_tones_from_77bits(message77,itone)
+! 0.1 K1ABC RR73; W9XYZ <KH1/KH7Z> -11 28 28 10 5 71 DXpedition Mode
+ i3bit=0
+ if(i3.eq.0 .and. n3.eq.1) i3bit=1
+! iFreeText=message77(57)
+! 0.0 Free text
+ if(i3.eq.0 .and. n3.eq.0) then
+ lFreeText=.true.
+ else
+ lFreeText=.false.
+ endif
+! delete braces
+ lcall2hash=.false.
+ if(.not.lFreeText .and. i3bit.ne.1 .and. index(msg37,'<').gt.0) then
+ if(index(msg37,'<').gt.4) lcall2hash=.true.
+ if(index(msg37,'<').gt.0) then
+ lhashmsg=.true.
+ endif
+ endif
+ if(nbadcrc.eq.0) exit
+ enddo ! ap passes
+ if(nbadcrc.eq.0) exit
+ enddo ! weak sigs
+ if(nbadcrc.eq.0) exit
+ enddo !nqso sync
+
+2 if(nbadcrc.eq.0) then
+! check for the false FT8Svar decode
+ if(lft8s .and. lrepliedother) then
+ msg37=''
+ nbadcrc=1
+ return
+ endif
+ msg37_2=''
+ if(i3bit.eq.1 .and. .not.lft8s .and. .not.lft8sd) then
+ call msgparservar(msg37,msg37_2)
+ lspecial=.true. !only in ft8var
+
+!protection against a false FT8Svar decode in Hound mode
+ if(lhound .and. dfqso.lt.2.0) lqsomsgdcd=.true. !$OMP FLUSH (lqsomsgdcd)
+ endif
+ qual=1.0-(nharderrors+dmin)/60.0
+ xsnr=0.001
+ xnoi=1.E-8
+ xsnrtmp=0.001
+ do i=1,79
+ xsig=s8(itone(i),i)**2
+ xnoi=(sum(s8(0:7,i)**2) - xsig)/7.0
+ if(xnoi.lt.0.01) xnoi=0.01 ! safe division and better accuracy
+ if(xnoi.lt.xsig) then
+ xsnr=xsig/xnoi
+ else
+ xsnr=1.01
+ endif
+ xsnrtmp=xsnrtmp+xsnr
+ enddo
+
+ xsnr=xsnrtmp/79.0-1.0
+ xsnr=10.0*log10(xsnr)-26.5
+ if(xsnr.gt.7.0) xsnr=xsnr+(xsnr-7.0)/2.0
+ if(xsnr.gt.30.0) then
+ xsnr=xsnr-1.0
+ if(xsnr.gt.40.0) xsnr=xsnr-1.0
+ if(xsnr.gt.49.0) xsnr=49.0
+ endif
+ xsnrs=xsnr
+ if(xsnr .lt. -17.0) then
+ if(xsnr.lt.-22.5 .and. xsnr.gt.-23.5) xsnr=-22.5 ! safe division and better accuracy
+ xsnr=xsnr-(1.0+1.4/(23.0+xsnr))**2+1.2
+ endif
+ if(iaptype.eq.0) then
+ if(xsnr.lt.-23.0) xsnr=-23.0
+ else
+ if(xsnr.lt.-24.0) xsnr=-24.0
+ endif
+ if(lft8s .or. lft8sd) then
+ if(xsnr.lt.-22.0) xsnr=xsnrs-1.0 ! correction offset
+ if(xsnr.lt.-26.0) xsnr=-26.0
+
+! -26 0.1 1477 ~ AC1MX AC1MX R-17 ^
+ if(len_trim(mycall).gt.3 .and. index(msg37,' '//trim(mycall)//' ').gt.1) then
+ msg37=''
+ return
+ endif
+ go to 4 ! bypass checking to false decode
+ endif
+ !if(len_trim(msg37)>0) print*,'line 2371 ',msg37
+
+ rxdt=xdt-0.5
+ if(iaptype.gt.34 .and. iaptype.lt.40) then ! DX Call searching false iaptype 35,36: 'CS7CYU/R FO5QB 73', 'T57KWP/R FO5QB RR73'
+ ispc1=index(msg37,' ')
+ if(ispc1.gt.5) then
+ if(msg37((ispc1-2):(ispc1-1)).eq.'/R') then ! have to cascade it to prevent getting out of index range
+ call_a=''
+ call_a=msg37(1:(ispc1-3))
+ lfound=.false.
+ call searchcallsvar(call_a," ",lfound)
+ if(.not.lfound) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ else if(qual.lt.0.39 .or. xsnr.lt.-20.5 .or. rxdt.lt.-0.5 .or. rxdt.gt.1.9 &
+ .or. (iaptype.gt.0 .and. iaptype.lt.4) .or. iaptype.eq.11 .or. &
+ iaptype.eq.21 .or. iaptype.eq.40 .or. iaptype.eq.41) then
+ if(iaptype.gt.3 .and. iaptype.lt.7) go to 4 ! skip, nothing to check
+ if(iaptype.ne.2 .and. iaptype.ne.3 .and. iaptype.ne.11 .and. iaptype.ne.21 &
+ .and. iaptype.ne.40 .and. iaptype.ne.41) then
+ if((mybcall.ne." " .and. index(msg37,mybcall).gt.0) .or. &
+ (hisbcall.ne." " .and. index(msg37,hisbcall).gt.0)) go to 256
+ endif
+
+ if(i3bit.eq.1) then
+ ! print*,'nbadcrc line 2400',nbadcrc
+ call chkspecial8var(msg37,msg37_2,nbadcrc)
+ ! print*,'nbadcrc line 2402',nbadcrc
+ else
+ ! print*,'nbadcrc line 2404 nbadcrc,i3,n3',nbadcrc,i3,n3
+ call chkfalse8var(msg37,i3,n3,nbadcrc,iaptype,lcall1hash)
+ ! print*,'nbadcrc line 2406',nbadcrc
+ endif
+ if(nbadcrc.eq.1) then
+ msg37=''
+ return
+ endif
+ endif
+ if(iaptype.eq.2 .or. iaptype.eq.3 .or. iaptype.eq.11 .or. iaptype.eq.21 .or. &
+ iaptype.eq.40 .or. iaptype.eq.41) go to 4 ! already checked
+
+! decoded without AP masks:
+! CQ PLIB U40OKH FE61
+! CQ 000 RO8JSV GJ38
+256 if(iaptype.eq.0 .and. i3.eq.1 .and. msg37(1:3).eq.'CQ ') then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if((ispc2-ispc1).eq.4 .or. (ispc2-ispc1).eq.5) then
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ if((ispc3-ispc2).gt.3 .and. (ispc4-ispc3).eq.5) then
+ grid=''
+ if(msg37(ispc3+1:ispc3+1).gt.'@' .and. msg37(ispc3+1:ispc3+1).lt.'S' &
+ .and. msg37(ispc3+2:ispc3+2).gt.'@' .and. &
+ msg37(ispc3+2:ispc3+2).lt.'S' .and. &
+ msg37(ispc3+3:ispc3+3).lt.':' .and. &
+ msg37(ispc3+4:ispc3+4).lt.':') grid=msg37(ispc3+1:ispc4-1)
+ if(grid.ne.'') then
+ callsign=''
+ callsign=msg37(ispc2+1:ispc3-1)
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+ endif
+
+! i3=1,2 false decodes with ' R '
+! 3B4NDC/R C40AUZ/R R IR83 i3=1
+! MS8QQS UX3QBS/P R NG63 i3=2
+! <...> P32WRF R LR56
+! P32WRF <...> R LR56
+
+ if((i3.eq.1 .or. i3.eq.2) .and. index(msg37,' R ').gt.0) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(ispc3-ispc2.eq.2) then
+ if(msg37(ispc2:ispc3).eq.' R ') then
+ call_b=''
+ if((i3.eq.1 .and. msg37(ispc2-2:ispc2-1).eq.'/R') .or. &
+ (i3.eq.2 .and. msg37(ispc2-2:ispc2-1).eq.'/P')) then
+ call_b=msg37(ispc1+1:ispc2-3)
+ else
+ call_b=msg37(ispc1+1:ispc2-1)
+ endif
+ if(lcall2hash) then ! valid call_b can be found in hash table, check call_a then
+ call_a=''
+ if((i3.eq.1 .and. msg37(ispc1-2:ispc1-1).eq.'/R') .or. &
+ (i3.eq.2 .and. msg37(ispc1-2:ispc1-1).eq.'/R')) then
+ call_a=msg37(1:ispc1-3)
+ else
+ call_a=msg37(1:ispc1-1)
+ endif
+ falsedec=.false.
+ call chkflscallvar('CQ ',call_a,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ else if(len_trim(call_b).gt.2) then
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ grid=''
+ if(ispc4-ispc3.eq.5 .and. msg37(ispc3+1:ispc3+1).gt.'@' .and. &
+ msg37(ispc3+1:ispc3+1).lt.'S' .and. &
+ msg37(ispc3+2:ispc3+2).gt.'@' .and. &
+ msg37(ispc3+2:ispc3+2).lt.'S' .and. &
+ msg37(ispc3+3:ispc3+3).lt.':' .and. &
+ msg37(ispc3+4:ispc3+4).lt.':') grid=msg37(ispc3+1:ispc4-1)
+ if(grid.ne.'') then
+ call chkgridvar(call_b,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+ endif
+ endif
+
+! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! -23 3.1 197 ~ Z67BGE H67HJI 22G EMA i3=0 n3=4
+! -3 2.2 FY4IML UV7BEA R 24F NNJ i3=0 n3=4
+
+ if(i3.eq.0 .and. n3.gt.2 .and. n3.lt.5) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(ispc1.gt.3 .and. ispc2.gt.7) then
+ call_a=''
+ call_b=''
+ if(msg37(1:ispc1-1).eq.'/R' .or. msg37(1:ispc1-1).eq.'/P') then
+ call_a=msg37(1:ispc1-3)
+ else
+ call_a=msg37(1:ispc1-1)
+ endif
+ if(msg37(ispc1+1:ispc2-1).eq.'/R' .or. msg37(ispc1+1:ispc2-1).eq.'/P') then
+ call_b=msg37(ispc1+1:ispc2-3)
+ else
+ call_b=msg37(ispc1+1:ispc2-1)
+ endif
+
+! operators outside USA and Canada shall transmit ' DX '
+ if(call_b(1:1).ne.'A' .and. call_b(1:1).ne.'K' .and. call_b(1:1).ne.'N' &
+ .and. call_b(1:1).ne.'W' .and. call_b(1:1).ne.'V' .and. &
+ call_b(1:1).ne.'C' .and. call_b(1:1).ne.'X') then
+ if(index(msg37,' DX ').lt.1) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+
+! USA AA..AL
+ if(call_b(1:1).eq.'A' .and. (call_b(2:2).lt.'A' .or. call_b(2:2).gt.'L')) then
+ if(index(msg37,' DX ').lt.1) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+
+! Canada CF..CK,CY,CZ,VA..VG,VO,VX,VY,XJ..XO
+ if(call_b(1:1).eq.'C' .and. (call_b(2:2).lt.'F' .or. call_b(2:2).gt.'K')) then
+ if(call_b(2:2).ne.'Y' .and. call_b(2:2).ne.'Z') then
+ if(index(msg37,' DX ').lt.1) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+
+ if(call_b(1:1).eq.'V' .and. (call_b(2:2).lt.'A' .or. call_b(2:2).gt.'G')) then
+ if(call_b(2:2).ne.'O' .and. call_b(2:2).ne.'X' .and. call_b(2:2).ne.'Y') then
+ if(index(msg37,' DX ').lt.1) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ if(call_b(1:1).eq.'X' .and. (call_b(2:2).lt.'J' .or. call_b(2:2).gt.'O')) then
+ if(index(msg37,' DX ').lt.1) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ if(xsnr.lt.-19.0 .or. rxdt.lt.-0.5 .or. rxdt.gt.1.0) then
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+
+! EU VHF contest exchange i3=5
+! <PA3XYZ> <G4ABC/P> R 590003 IO91NP h12 h22 r1 s3 S11 g25
+! packing is not implemented in WSJT-X 2.5.4?
+! old implementation with i3=0 n3=2
+! JL6GSC/P R 571553 CJ76MV i3=5
+! G59XTB R 521562 RA82SJ
+
+ if(i3.eq.5 .and. n3.eq.1 .and. (xsnr.lt.-19.0 .or. rxdt.lt.-0.5 .or. &
+ rxdt.gt.1.0)) then ! was if i3-0 and n3=2
+ ispc1=index(msg37,' ')
+ if(ispc1.gt.3) then
+ call_b=''
+ if(msg37(ispc1-2:ispc1-1).eq.'/P') then
+ call_b=msg37(1:ispc1-3)
+ else
+ call_b=msg37(1:ispc1-1)
+ endif
+ falsedec=.false.
+ call chkflscallvar('CQ ',call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+
+! FT8OPG/R Z27HRN/R OH12 check all standard messages with contest callsigns
+! /P has i3.eq.2 .and. n3.eq.0
+ if(iaptype.eq.0 .and. i3.eq.1 .and. n3.eq.0 .and. index(msg37,'/R ').gt.3) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(ispc1.gt.3 .and. ispc2.gt.6) then
+ call_a=''
+ call_b=''
+ if(msg37(ispc1-2:ispc1-1).eq.'/R') then
+ call_a=msg37(1:ispc1-3)
+ else
+ call_a=msg37(1:ispc1-1)
+ endif
+ if(msg37(ispc2-2:ispc2-1).eq.'/R') then
+ call_b=msg37(ispc1+1:ispc2-3)
+ else
+ call_b=msg37(ispc1+1:ispc2-1)
+ endif
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+
+! -23 -0.5 2533 ~ <...> W LKNQZG2K4 RR73 invalid message, iaptype=0 this type of message is not allowed for transmission with RR73
+! -23 -1.2 1335 ~ <...> Z7VENB8R G9 RRR non AP decode, iaptype=0 invalid message, this type of message is not allowed
+! for transmission with RRR
+
+ if(msg37(1:2).eq.'<.') then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ if((ispc4-ispc3.eq.4 .and. msg37(ispc3+1:ispc4-1).eq.'RRR') .or. &
+ (ispc4-ispc3.eq.5 .and. msg37(ispc3+1:ispc4-1).eq.'RR73') .or. &
+ (ispc4-ispc3.eq.3 .and. msg37(ispc3+1:ispc4-1).eq.'73')) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+
+! -19 0.0 2256 ~ <...> 9T4DQZ RP53 non AP decode, iaptype=0 i3=1 n3=1 SAME AS CQ MSG
+! <...> 9T4DQZ -15(R-15) message has i3=1 n3=4
+ if(i3.eq.1 .and. n3.eq.1 .and. (xsnr.lt.-18.0 .or. rxdt.lt.-0.5 .or. &
+ rxdt.gt.1.0)) then
+ callsign=' '
+ callsign=msg37(ispc1+1:ispc2-1)
+ grid=msg37(ispc2+1:ispc3-1)
+ include 'callsign_q.f90'
+ call chkgridvar(callsign,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ if(lchkcall .or. .not.lgvalid) then
+ falsedec=.false.
+ call chkflscallvar('CQ ',callsign,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+
+! -22 0.3 1000 ~ 9Y4DWY <...> BF70 iaptype=0 i3=1 n3=2 invalid message in FT8
+! protocol, can be transmitted manually
+
+ if(i3.eq.1) then
+ ispc1=index(msg37,' ')
+ if(msg37(ispc1+1:ispc1+2).eq.'<.') then
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(ispc3-ispc2.eq.5 .and. msg37(ispc2+1:ispc2+1).gt.'@' .and. &
+ msg37(ispc2+1:ispc2+1).lt.'S' .and. &
+ msg37(ispc2+2:ispc2+2).gt.'@' .and. &
+ msg37(ispc2+2:ispc2+2).lt.'S' .and. &
+ msg37(ispc2+3:ispc2+3).lt.':' .and. &
+ msg37(ispc2+4:ispc2+4).lt.':') then ! there is a valid grid in message
+ call_b=''
+ call_b=msg37(1:ispc1-1)
+ falsedec=.false.
+ call chkflscallvar('CQ ',call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+
+! i3=3 parse ARRL RTTY contest message
+! i3 n3 Bits Total Message type
+! 3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest
+! 3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX)
+! TU; D47IAQ <...> 559 032' does protocol support the message?
+
+ if(i3.eq.3 .and. msg37(1:3).eq.'TU;') then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ call_a=''
+ call_b=''
+ call_a=msg37(ispc1+1:ispc2-1)
+ call_b=msg37(ispc2+1:ispc3-1)
+! check for false, too tough, need to rework if contest is supported
+ falsedec=.false.
+ call chkflscallvar(call_a,call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+! parse
+ lspecial=.true.
+ msg37_2=msg37(5:37)//' '
+ msg37=''
+ msg37='DE '//trim(call_b)//' TU'
+ endif
+
+! DX Call searching false decodes, search for 1st callsign in ALLCALL7
+! 6W6VIV EY8MM 73
+! 6Y9KOZ EY8MM RR73
+ if(iaptype.gt.34 .and. iaptype.lt.40 .and. (xsnr.lt.-21.0 .or. rxdt.lt.-0.5 &
+ .or. rxdt.gt.1.0)) then
+ ispc1=index(msg37,' ')
+ if(ispc1.gt.1) then
+ call_b=''
+ call_b=msg37(1:ispc1-1)
+ falsedec=.false.
+ call chkflscallvar('CQ ',call_b,falsedec)
+ if(falsedec) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+
+4 continue
+!### Possibly call ft8_a8d() here ??? ###
+
+ ldupemsg=.false.
+ if(ndecodes.gt.0) then
+ do i=1,ndecodes
+ if(allmessages(i).eq.msg37 .and. abs(allfreq(i)-f1).lt.45.0) then
+ ldupemsg=.true.
+ endif
+ enddo
+ endif
+
+ if(.not.ldupemsg .and. dfqso.lt.2.0 .and. ((i3.eq.1 .and. .not.lft8s) .or. &
+ lft8s)) then
+ if(msg37(1:msgrootlen+1).eq.trim(msgroot)//' ') then
+ lasthcall=hiscall
+ lastrxmsg(1)%lastmsg=msg37
+ lastrxmsg(1)%xdt=xdt-0.5
+ lastrxmsg(1)%lstate=.true.
+ lqsomsgdcd=.true.
+!$OMP FLUSH (lqsomsgdcd)
+ else if(.not.lft8s .and. mycalllen1.gt.2) then
+ if(msg37(1:mycalllen1).ne.trim(mycall)//' ' .and. &
+ index(msg37,' '//trim(hiscall)//' ').gt.0) then
+ lrepliedother=.true.
+ endif
+ endif
+ endif
+
+ if(len_trim(hiscall).gt.3 .and. .not.lqsomsgdcd) then
+ if(msg37(1:msgrootlen+1).eq.trim(msgroot)//' ') then
+ lqsomsgdcd=.true.
+!$OMP FLUSH (lqsomsgdcd)
+ endif
+ endif
+
+ if(.not.stophint .and. .not.ldupemsg .and. dfqso.lt.2.0 .and. nlasttx.gt.0 &
+ .and. nlasttx.lt.6 .and. msg37(1:3).eq.'CQ ') then
+ nlength=len_trim(hiscall)
+ if(nlength.gt.2) then
+ if(msg37(4:4+nlength).eq.trim(hiscall)//' ' .or. &
+ msg37(7:7+nlength).eq.trim(hiscall)//' ') lrepliedother=.true.
+ endif
+ endif
+
+ if(mycalllen1.gt.2) then
+ if(.not.ldupemsg .and. msg37(1:mycalllen1).eq.trim(mycall)//' ') then
+ nincallthr(nthr)=nincallthr(nthr)+1
+ nindex=maskincallthr(nthr)+nincallthr(nthr)
+ if(nindex.lt.maskincallthr(nthr+1)) then
+ msgincall(nindex)=msg37
+ xdtincall(nindex)=xdt-0.5
+ else
+ nincallthr(nthr)=nincallthr(nthr)-1
+ endif
+ endif
+ endif
+
+ ldupeft8sd=.false.
+ if(ncount.gt.0 .and. lft8sd) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ msgbase37=''
+ msgbase37=msg37(1:ispc2-1)
+ do i=1,ncount
+ if(trim(msgbase37).eq.trim(msgsrcvd(i))) then
+ ldupeft8sd=.true.
+ exit
+ endif
+ enddo
+ endif
+
+ if(ldupeft8sd) then
+ msg37=''
+ nbadcrc=1
+ return
+ endif
+
+ if(.not.ldupemsg .and. i3.eq.1 .and. .not.lft8sd .and. .not.lft8s .and. &
+ msg37(1:3).ne.'CQ ') then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ncount=ncount+1
+ msgsrcvd(ncount)=msg37(1:ispc2-1)
+ endif
+
+! -23 0.0 1606 ~ <...> 3U1TBM/R CC65 i3=4 n3=0
+! -18 0.3 1609 ~ CQ 6U6MBL/R IJ90 i3=1 in some noisy setups false decode with any SNR value is possible
+
+ if((i3.eq.4 .and. n3.eq.0) .or. (i3.eq.1 .and. msg37(1:3).eq."CQ ")) then
+ if(index(msg37,'/R ').gt.9) then
+ ispc1=index(msg37,' ')
+ ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ if(ispc2.gt.11) then
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2
+ if(msg37((ispc2-2):(ispc2-1)).eq.'/R') then
+ if((ispc3-ispc2).eq.5) then
+ grid=msg37(ispc2+1:ispc3-1)
+! grid can not be txed, invalid message:
+ if(i3.eq.4 .and. len_trim(grid).eq.4) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ call_b=''
+ call_b=msg37((ispc1+1):(ispc2-3))
+ call chkgridvar(call_b,grid,lchkcall,lgvalid,lwrongcall)
+ if(lwrongcall .or. .not.lgvalid) then
+ nbadcrc=1
+ msg37=''
+ return
+ endif
+ endif
+ endif
+ endif
+ endif
+ endif
+
+! protocol violations
+! 713STG 869TK NO05 i3=2 n3=5, false decode, as per protocol type2 shall be /P message
+ if(i3.eq.2 .and. index(msg37,'/P ').lt.1) then
+ msg37=''
+ nbadcrc=1
+ return
+ endif
+
+! -18 0.5 584 ~ UA3ALE <...> PR07 * AP decode with grid
+ if(iaptype.eq.2) then
+ nhash=index(msg37,"<...>")
+ if(nhash.gt.4 .and. nhash.lt.13 .and. msg37(nhash+6:nhash+6).gt.'@' .and. &
+ msg37(nhash+7:nhash+7).gt.'@') then
+ msg37=''
+ nbadcrc=1
+ return
+ endif
+ endif
+
+ if(lsubtract) then
+ noff=10
+ sync0=0.
+ syncp=0.
+ syncm=0.
+ k=1
+ call gen_ft8wavevar(itone,79,1920,2.0,12000.0,0.0,csig0,xjunk,1,151680)
+ do i=0,78
+ do j=1,32
+ csig(j)=csig0(k)
+ k=k+60
+ enddo
+ i21=i0+i*32
+ z1=0.
+ z1=sum(cd0(i21:i21+31)*conjg(csig))
+ sync0 = sync0 + real(z1)**2 + aimag(z1)**2
+ i21=i0+i*32+noff
+ z1=0.
+ z1=sum(cd0(i21:i21+31)*conjg(csig))
+ syncp = syncp + real(z1)**2 + aimag(z1)**2
+ i21=i21-noff*2
+ z1=0.
+ z1=sum(cd0(i21:i21+31)*conjg(csig))
+ syncm = syncm + real(z1)**2 + aimag(z1)**2
+ enddo
+ call peakup(syncm,sync0,syncp,dx)
+ if(abs(dx).gt.1.0) then
+ scorr=0.
+ else
+ scorr=real(noff)*(dx) ! was * dx ft8md
+ endif
+ xdt3=xdt+scorr*dt2
+ call subtractft8var(itone,f1,xdt3)
+ lsubtracted=.true. ! inside current thread
+ if(npos.lt.200) then
+ npos=npos+1
+ freqsub(npos)=f1
+ endif
+ endif
+ endif
+
+ return
+end subroutine ft8bvar
+
+subroutine normalizebmetvar(bmet,n)
+ real bmet(n)
+
+! bmetav=sum(bmet)/real(n)
+ bmet2av=sum(bmet*bmet)/real(n)
+! var=bmet2av-bmetav*bmetav
+! if( var .gt. 0.0 ) then
+! bmetsig=sqrt(var)
+! else
+ bmetsig=sqrt(bmet2av)
+! endif
+ bmet=bmet/bmetsig
+
+ return
+end subroutine normalizebmetvar
diff --git a/lib/ft8var/ft8mf1var.f90 b/lib/ft8var/ft8mf1var.f90 new file mode 100755 index 00000000..f9c1d784 --- /dev/null +++ b/lib/ft8var/ft8mf1var.f90 @@ -0,0 +1,81 @@ +
+subroutine ft8mf1var(s8,itone,msgd,msg37,lft8sd)
+
+ use ft8_mod1, only : itone76,idtone76,msgsd76
+ real, intent(in) :: s8(0:7,79)
+ real s8d(0:7,58)
+ character msgd*37,msg37*37,msggrid*37,c1*12,c2*12,grid*4
+ integer itone(79),mrs(58),mrs2(58)
+ logical(1) lft8sd,lr73,lgrid,lreport,lrreport,lrrr
+
+ lr73=.false.; lgrid=.false.; lreport=.false.; lrreport=.false.; lrrr=.false.
+ c1=' '; c2=' '
+ ispc1=index(msgd,' '); ispc2=index(msgd((ispc1+1):),' ')+ispc1; ispc3=index(msgd((ispc2+1):),' ')+ispc2
+ if(len(msgd(1:ispc1-1)).le.12 .and. len(msgd(ispc1+1:ispc2-1)).le.12) then
+ c1=msgd(1:ispc1-1); c2=msgd(ispc1+1:ispc2-1)
+ else
+ return
+ endif
+ if(len_trim(c1).lt.3 .or. len_trim(c2).lt.3) return
+ if(msgd(ispc2+1:ispc3-1).eq.'RR73' .or. msgd(ispc2+1:ispc3-1).eq.'73') lr73=.true.
+ if(.not.lr73 .and. (ispc3-ispc2).eq.5 .and. msgd(ispc2+1:ispc2+2).ne.'R+' .and. msgd(ispc2+1:ispc2+2).ne.'R-') &
+ lgrid=.true.
+ if(msgd(ispc2+1:ispc2+1).eq.'+' .or. msgd(ispc2+1:ispc2+1).eq.'-') lreport=.true.
+ if(msgd(ispc2+1:ispc2+2).eq.'R+' .or. msgd(ispc2+1:ispc2+2).eq.'R-') lrreport=.true.
+ if(msgd(ispc2+1:ispc3-1).eq.'RRR') lrrr=.true.
+
+ thresh=0.0; i1=0; i2=0
+ do i=1,58; if(i.le.29) then; s8d(0:7,i)=s8(0:7,i+7); else; s8d(0:7,i)=s8(0:7,i+14); endif; enddo
+ do j=1,58
+ s1=-1.0E6; s2=-1.0E6
+ do i=0,7; if(s8d(i,j).gt.s1) then; s1=s8d(i,j); i1=i; endif; enddo
+ do i=0,7; if(i.ne.i1 .and. s8d(i,j).gt.s2) then; s2=s8d(i,j); i2=i; endif; enddo
+ mrs(j)=i1; mrs2(j)=i2
+ enddo
+ ref0=0.0
+ do i=1,58; ref0=ref0 + s8d(mrs(i),i); enddo
+
+ ipk=0; u1=0.0; u2=0.0
+ do k=1,76
+ psum=0.; ref=ref0
+ do j=1,58; i3=idtone76(k,j); psum=psum + s8d(i3,j); if(i3.eq.mrs(j)) ref=ref - s8d(i3,j) + s8d(mrs2(j),j); enddo
+ p=psum/ref
+ if(p.gt.u1) then; u2=u1; u1=p; ipk=k
+ else; if(p.gt.u2) u2=p
+ endif
+ enddo
+!/'+09 ','+08 ','+07 ','+06 ','+05 ','+04 ','+03 ','+02 ','+01 ','+00 ', &
+! '-01 ','-02 ','-03 ','-04 ','-05 ','-06 ','-07 ','-08 ','-09 ','-10 ', &
+! '-11 ','-12 ','-13 ','-14 ','-15 ','-16 ','-17 ','-18 ','-19 ','-20 ', &
+! '-21 ','-22 ','-23 ','-24 ','-25 ','-26 ','R+09','R+08','R+07','R+06', &
+! 'R+05','R+04','R+03','R+02','R+01','R+00','R-01','R-02','R-03','R-04', &
+! 'R-05','R-06','R-07','R-08','R-09','R-10','R-11','R-12','R-13','R-14', &
+! 'R-15','R-16','R-17','R-18','R-19','R-20','R-21','R-22','R-23','R-24', &
+! 'R-25','R-26','RRR ','RR73','73 ','AA00'/
+ if(ipk.ne.0) then
+ if(lgrid) then
+ if(ipk.eq.76) then
+ msggrid=msgsd76(76)
+ ispc1=index(msggrid,' '); ispc2=index(msggrid((ispc1+1):),' ')+ispc1; ispc3=index(msggrid((ispc2+1):),' ')+ispc2
+ grid=msggrid(ispc2+1:ispc3-1)
+ if(grid.eq.'AA00') return
+ endif
+ if(ipk.lt.37 .or. (ipk.gt.72 .and. ipk.lt.76)) return
+ endif
+ if(lreport) then; if((ipk.gt.36 .and. ipk.lt.73) .or. ipk.eq.76) return; endif
+ if(lrreport) then; if(ipk.lt.37 .or. ipk.eq.73 .or. ipk.eq.76) return; endif
+ if(lrrr) then; if(ipk.lt.73 .or. ipk.eq.76) return; endif
+ if(lr73) then; if(ipk.lt.74 .or. ipk.eq.76) return; endif
+
+ qual=100.0*(u1-u2)
+ thresh=(qual+10.0)*(u1-0.6)
+ if(thresh.gt.4.0 .and. qual.gt.2.6 .and. u1.gt.0.77) then
+!print *,'matched',thresh
+!print *,msgsd76(ipk)
+! if(trim(msgsd76(ipk)).eq.'CQ DE AA00') return ! triggered by memory corruption?
+ lft8sd=.true.; msg37=msgsd76(ipk); itone(1:79)=itone76(ipk,1:79); return
+ endif
+ endif
+
+ return
+end subroutine ft8mf1var
diff --git a/lib/ft8var/ft8mfcqvar.f90 b/lib/ft8var/ft8mfcqvar.f90 new file mode 100755 index 00000000..9f6ccddf --- /dev/null +++ b/lib/ft8var/ft8mfcqvar.f90 @@ -0,0 +1,51 @@ +
+subroutine ft8mfcqvar(s8,itone,msgd,msg37,lft8sd)
+
+ use ft8_mod1, only : idtone25
+ real, intent(in) :: s8(0:7,79)
+ real s8d(0:7,58)
+ character*37 msgd,msg37,msgsent37
+ integer itone(79),mrs(58),mrs2(58)
+ integer*1 msgbits(77)
+ logical(1) lft8sd
+
+ if(len_trim(msgd).lt.6) return
+ i3=-1; n3=-1
+ call genft8sdvar(msgd,i3,n3,msgsent37,msgbits,itone)
+ idtone25(1,1:29)=itone(8:36)
+ idtone25(1,30:58)=itone(44:72)
+
+ thresh=0.0; i1=0; i2=0
+ do i=1,58; if(i.le.29) then; s8d(0:7,i)=s8(0:7,i+7); else; s8d(0:7,i)=s8(0:7,i+14); endif; enddo
+ do j=1,58
+ s1=-1.0E6; s2=-1.0E6
+ do i=0,7; if(s8d(i,j).gt.s1) then; s1=s8d(i,j); i1=i; endif; enddo
+ do i=0,7; if(i.ne.i1 .and. s8d(i,j).gt.s2) then; s2=s8d(i,j); i2=i; endif; enddo
+ mrs(j)=i1; mrs2(j)=i2
+ enddo
+ ref0=0.0
+ do i=1,58; ref0=ref0 + s8d(mrs(i),i); enddo
+
+ ipk=0; u1=0.0; u2=0.0
+ do k=1,25
+ psum=0.; ref=ref0
+ do j=1,58; i3=idtone25(k,j); psum=psum + s8d(i3,j); if(i3.eq.mrs(j)) ref=ref - s8d(i3,j) + s8d(mrs2(j),j); enddo
+ p=psum/ref
+ if(p.gt.u1) then; u2=u1; u1=p; ipk=k
+ else; if(p.gt.u2) u2=p
+ endif
+ enddo
+
+ if(ipk.eq.1) then
+ qual=100.0*(u1-u2)
+ thresh=(qual+10.0)*(u1-0.6)
+ if(thresh.gt.4.0 .and. qual.gt.2.6 .and. u1.gt.0.77) then
+!print *,'matched',thresh
+!print *,msgsd76(ipk)
+! if(msgd(1:10).eq.'CQ DE AA00') return ! triggered by memory corruption?
+ lft8sd=.true.; msg37=msgd; return
+ endif
+ endif
+
+ return
+end subroutine ft8mfcqvar
diff --git a/lib/ft8var/ft8sd1var.f90 b/lib/ft8var/ft8sd1var.f90 new file mode 100755 index 00000000..05ae3005 --- /dev/null +++ b/lib/ft8var/ft8sd1var.f90 @@ -0,0 +1,113 @@ +subroutine ft8sd1var(s8,itone,msgd,msg37,lft8sd,lcq)
+
+ use ft8_mod1, only : mycall
+ real, intent(in) :: s8(0:7,79)
+ real s8_1(0:7,79)
+ character msgd*37,msg37*37,msg372*37,msgsent37*37,c1*12,c2*12
+ character*37 msg4(4)
+ integer idtone4(4,58),itone4(4,79)
+ integer itone(79),itonedem(58),idtone(58),ip1(1)
+ integer*1 msgbits(77)
+ logical(1), intent(in) :: lcq
+ logical(1) lft8sd,lr73,lgrid,lmatched(58)
+
+ lmatched=.false.; lr73=.false.; lgrid=.false.
+ itonedem=11
+
+ if(.not.lcq) then
+ c1=' '; c2=' '
+ ispc1=index(msgd,' '); ispc2=index(msgd((ispc1+1):),' ')+ispc1; ispc3=index(msgd((ispc2+1):),' ')+ispc2
+ if(len(msgd(1:ispc1-1)).le.12 .and. len(msgd(ispc1+1:ispc2-1)).le.12) then
+ c1=msgd(1:ispc1-1); c2=msgd(ispc1+1:ispc2-1)
+ else
+ return
+ endif
+ if(len_trim(c1).lt.3 .or. len_trim(c2).lt.3 .or. c2.eq.trim(mycall)) return
+ if(index(msgd,' RR73').gt.0 .or. index(msgd,' 73').gt.0) lr73=.true.
+ if(.not.lr73 .and. (ispc3-ispc2).eq.5 .and. msgd(ispc2+1:ispc2+2).ne.'R+' &
+ .and. msgd(ispc2+1:ispc2+2).ne.'R-') lgrid=.true.
+ if(.not.lgrid .and. .not.lr73) then
+ do i=1,4
+ msg4(i)=' '
+ if(i.eq.1) msg4(i)=msgd
+ if(i.eq.2) msg4(i)=trim(c1)//' '//trim(c2)//' RRR'
+ if(i.eq.3) msg4(i)=trim(c1)//' '//trim(c2)//' RR73'
+ if(i.eq.4) msg4(i)=trim(c1)//' '//trim(c2)//' 73'
+ enddo
+ endif
+ endif
+
+ if(lcq .or. lgrid .or. lr73) then
+ i3=-1; n3=-1
+ msg372=msgd
+ call genft8sdvar(msg372,i3,n3,msgsent37,msgbits,itone)
+ idtone(1:29)=itone(8:36)
+ idtone(30:58)=itone(44:72)
+ else
+ do i=1,4
+ msg372=msg4(i)
+ i3=-1; n3=-1
+ call genft8sdvar(msg372,i3,n3,msgsent37,msgbits,itone)
+ idtone4(i,1:29)=itone(8:36)
+ idtone4(i,30:58)=itone(44:72)
+ itone4(i,1:79)=itone(1:79)
+ enddo
+ endif
+
+ s8_1=s8
+ do i=1,58
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+
+ imax=0
+ if(lcq .or. lgrid .or. lr73) then
+ nmatch1=0; ncrcpaty1=0
+ do k=1,58
+ if(idtone(k).eq.itonedem(k)) then; nmatch1=nmatch1+1; if(k.gt.25) ncrcpaty1=ncrcpaty1+1; endif
+ enddo
+ if(nmatch1.gt.29 .and. ncrcpaty1.gt.10) then; lft8sd=.true.; msg37=msgd; return; endif
+ else
+ nmatchditer1=0; ncrcpatyiter1=0
+ do i=1,4
+ nmatch1=0; ncrcpaty1=0
+ do k=1,58
+ if(idtone4(i,k).eq.itonedem(k)) then; nmatch1=nmatch1+1; if(k.gt.25) ncrcpaty1=ncrcpaty1+1; endif
+ enddo
+ if(nmatch1.gt.nmatchditer1) then; imax=i; nmatchditer1=nmatch1; ncrcpatyiter1=ncrcpaty1; endif
+ enddo
+ if(imax.eq.0) return
+ if(lr73 .and. imax.eq.2) return ! RRR is not a valid message
+ nmatch1=nmatchditer1; ncrcpaty1=ncrcpatyiter1
+ idtone(1:58)=idtone4(imax,1:58)
+ if(nmatch1.gt.29 .and. ncrcpaty1.gt.10) then; lft8sd=.true.; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); return; endif
+ endif
+
+ if(nmatch1.ge.22) then
+ do k=1,58
+ if(idtone(k).eq.itonedem(k)) lmatched(k)=.true.
+ enddo
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1)
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); endif
+ enddo
+
+ nmatch2=nmatch1; ncrcpaty2=ncrcpaty1
+ if(lcq .or. lgrid .or. lr73) then
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch2=nmatch2+1; if(k.gt.25) ncrcpaty2=ncrcpaty2+1; endif
+ enddo
+ if(nmatch2.gt.41 .and. ncrcpaty2.gt.19) then; lft8sd=.true.; msg37=msgd; return; endif
+ else
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch2=nmatch2+1; if(k.gt.25) ncrcpaty2=ncrcpaty2+1; endif
+ enddo
+ if(nmatch2.gt.41 .and. ncrcpaty2.gt.19) then; lft8sd=.true.; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); return; endif
+ endif
+ endif
+
+ return
+end subroutine ft8sd1var
diff --git a/lib/ft8var/ft8sdvar.f90 b/lib/ft8var/ft8sdvar.f90 new file mode 100755 index 00000000..ed8cb00a --- /dev/null +++ b/lib/ft8var/ft8sdvar.f90 @@ -0,0 +1,178 @@ +subroutine ft8sdvar(s8,srr,itone,msgd,msg37,lft8sd,lcq)
+
+ use ft8_mod1, only : mycall
+ real, intent(in) :: s8(0:7,79)
+ real s8_1(0:7,79)
+ character msgd*37,msg37*37,msg372*37,msgsent37*37,c1*12,c2*12
+ character*37 msg4(4)
+ integer idtone4(4,58),itone4(4,79)
+ integer itone(79),itonedem(58),idtone(58),ip1(1)
+ integer*1 msgbits(77)
+ logical(1), intent(in) :: lcq
+ logical(1) lft8sd,lmatched(58)
+
+ if(index(msgd,' RR73').gt.0 .or. index(msgd,' 73').gt.0) return ! do not process 73 messages
+! do not process messages with grid
+ if(.not.(msgd(1:3).eq.'CQ ' .or. index(msgd,'-').gt.0 .or. index(msgd,'+').gt.0 .or. index(msgd,' RRR').gt.0)) return
+
+ lmatched=.false.; s8_1=s8; itonedem=11
+
+ if(.not.lcq) then
+ c1=' '; c2=' '
+ ispc1=index(msgd,' '); ispc2=index(msgd((ispc1+1):),' ')+ispc1
+ if(len(msgd(1:ispc1-1)).le.12 .and. len(msgd(ispc1+1:ispc2-1)).le.12) then
+ c1=msgd(1:ispc1-1); c2=msgd(ispc1+1:ispc2-1)
+ else
+ return
+ endif
+ if(len_trim(c1).lt.3 .or. len_trim(c2).lt.3 .or. c2.eq.trim(mycall)) return
+ do i=1,4
+ msg4(i)=' '
+ if(i.eq.1) msg4(i)=msgd
+ if(i.eq.2) msg4(i)=trim(c1)//' '//trim(c2)//' RRR'
+ if(i.eq.3) msg4(i)=trim(c1)//' '//trim(c2)//' RR73'
+ if(i.eq.4) msg4(i)=trim(c1)//' '//trim(c2)//' 73'
+ enddo
+ endif
+
+ if(lcq) then
+ i3=-1; n3=-1
+ msg372=msgd
+ call genft8sdvar(msg372,i3,n3,msgsent37,msgbits,itone)
+ idtone(1:29)=itone(8:36)
+ idtone(30:58)=itone(44:72)
+ else
+ do i=1,4
+ msg372=msg4(i)
+ i3=-1; n3=-1
+ call genft8sdvar(msg372,i3,n3,msgsent37,msgbits,itone)
+ idtone4(i,1:29)=itone(8:36)
+ idtone4(i,30:58)=itone(44:72)
+ itone4(i,1:79)=itone(1:79)
+ enddo
+ endif
+
+ do i=1,58
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+
+ imax=0
+ if(lcq) then
+ nmatch1=0; ncrcpaty1=0
+ do k=1,58
+ if(idtone(k).eq.itonedem(k)) then; nmatch1=nmatch1+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty1=ncrcpaty1+1; endif
+ enddo
+ if(nmatch1.gt.26) then; lft8sd=.true.; msg37=msgd; return; endif
+ else
+ nmatchditer1=0; nbaseiter1=0; ncrcpatyiter1=0;
+ do i=1,4
+ nmatch1=0; nbase1=0; ncrcpaty1=0
+ do k=1,58
+ if(idtone4(i,k).eq.itonedem(k)) then
+ nmatch1=nmatch1+1; if(k.lt.23) nbase1=nbase1+1; if(k.gt.25) ncrcpaty1=ncrcpaty1+1 ! CRC+parity
+ endif
+ enddo
+ if(nmatch1.gt.nmatchditer1) then
+ imax=i; nmatchditer1=nmatch1; nbaseiter1=nbase1; ncrcpatyiter1=ncrcpaty1
+ endif
+ enddo
+ if(imax.eq.0) return
+ if(srr.gt.3.0 .and. nbaseiter1.lt.12) return ! prevent false decodes from the strong signals
+ nmatch1=nmatchditer1; ncrcpaty1=ncrcpatyiter1!; nbase1=nbaseiter1
+ idtone(1:58)=idtone4(imax,1:58)
+ if(nmatch1.gt.26 .and. ncrcpaty1.gt.10) then
+ lft8sd=.true.; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); return
+ endif
+ do k=1,58
+ if(idtone(k).eq.itonedem(k)) lmatched(k)=.true.
+ enddo
+ endif
+
+ if(nmatch1.ge.16) then
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch2=nmatch1; ncrcpaty2=ncrcpaty1
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch2=nmatch2+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty2=ncrcpaty2+1; endif
+ enddo
+ if(nmatch2.gt.38 .and. ncrcpaty2.gt.19) then
+ lft8sd=.true.
+ if(lcq) then; msg37=msgd; else; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); endif
+ return
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch3=nmatch2; ncrcpaty3=ncrcpaty2
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch3=nmatch3+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty3=ncrcpaty3+1; endif
+ enddo
+ if(nmatch3.gt.44 .and. ncrcpaty3.gt.21) then
+ lft8sd=.true.
+ if(lcq) then; msg37=msgd; else; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); endif
+ return
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch4=nmatch3; ncrcpaty4=ncrcpaty3
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch4=nmatch4+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty4=ncrcpaty4+1; endif
+ enddo
+ if(nmatch4.gt.47 .and. ncrcpaty4.gt.23) then
+ lft8sd=.true.
+ if(lcq) then; msg37=msgd; else; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); endif
+ return
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch5=nmatch4; ncrcpaty5=ncrcpaty4
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch5=nmatch5+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty5=ncrcpaty5+1; endif
+ enddo
+ if(nmatch5.gt.50 .and. (nmatch1.gt.21 .or. nmatch2.gt.31 .or. nmatch3.gt.38 .or. nmatch4.gt.46) .and. &
+ ncrcpaty5.gt.25) then
+ lft8sd=.true.
+ if(lcq) then; msg37=msgd; else; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); endif
+ return
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch6=nmatch5; ncrcpaty6=ncrcpaty5
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch6=nmatch6+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty6=ncrcpaty6+1; endif
+ enddo
+ if(nmatch6.gt.54 .and. (nmatch1.gt.22 .or. nmatch2.gt.27 .or. nmatch3.gt.35 .or. &
+ (nmatch2-nmatch1).gt.9 .or. (nmatch3-nmatch2).gt.10) .and. ncrcpaty6.gt.29) then
+ lft8sd=.true.
+ if(lcq) then; msg37=msgd; else; msg37=msg4(imax); itone(1:79)=itone4(imax,1:79); endif
+ return
+ endif
+
+ endif
+
+ return
+end subroutine ft8sdvar
diff --git a/lib/ft8var/ft8svar.f90 b/lib/ft8var/ft8svar.f90 new file mode 100755 index 00000000..83a4ac03 --- /dev/null +++ b/lib/ft8var/ft8svar.f90 @@ -0,0 +1,368 @@ +
+subroutine ft8svar(s8,srr,itone,msg37,lft8s,nft8rxfsens,stophint)
+
+ use ft8_mod1, only : itone56,idtone56,msg,nlasttx,lastrxmsg,mycall,hiscall
+ real, intent(in) :: s8(0:7,79),srr
+ real s8_1(0:7,79),s8d(0:7,58),xsync(21),xmsync(21),xdata(58),xmdata(58),xnoise(79),xmnoise(79)
+ character, intent(out) :: msg37*37
+ character*37 lastrcvdmsg,msgsent37
+ integer, intent(out) :: itone(79)
+ integer, intent(in) :: nft8rxfsens
+ integer itonedem(58),idtone(58),mrs(58),mrs2(58),mrs3(58),mrs4(58),ip1(1)
+ logical(1), intent(in) :: stophint
+ logical(1), intent(out) :: lft8s
+ logical(1) lmatched(58),lmycall,lhiscall,lrrr,lr73,lcallingrprt,lastrrprt,lastreport,lgrid
+
+! taken from ft8_mod1
+! integer itone56(56,79),idtone56(56,58)
+! character*37 msg(56)
+
+!nlasttx last TX message
+! 0 Tx was halted
+! 1 AA1AA BB1BB PL35
+! 2 AA1AA BB1BB -15
+! 3 AA1AA BB1BB R-15
+! 4 AA1AA BB1BB RRR/RR73
+! 5 AA1AA BB1BB 73
+! 6 CQ BB1BB PL35
+
+ lft8s=.false.
+ if(stophint) return; if(len_trim(hiscall).lt.3) return; if(nlasttx.eq.6 .or. nlasttx.eq.0) return ! CQ or TX halted
+ lgrid=.false.; nft8rxfslow=nft8rxfsens; lmycall=.false.; lastrcvdmsg=''
+ lmatched=.false.; s8_1=s8; lhiscall=.false.; lrrr=.false.; lr73=.false.; lcallingrprt=.false.; lastrrprt=.false.
+ lastreport=.false.; itonedem=11; ntresh1=26; ntresh2=38; if(srr.gt.7.0) then; ntresh1=29; ntresh2=41; endif
+
+ if(lastrxmsg(1)%lstate) then; lastrcvdmsg=lastrxmsg(1)%lastmsg; else; lastrcvdmsg=''; endif
+
+ if(lastrcvdmsg.ne.' ') then
+ if(index(lastrcvdmsg,trim(hiscall)).gt.0) lhiscall=.true.
+ if(index(lastrcvdmsg,trim(mycall)).eq.1) lmycall=.true.
+ if(lmycall .and. lhiscall) then
+ if(index(lastrcvdmsg,' RRR').gt.0) lrrr=.true.
+ if(index(lastrcvdmsg,' RR73').gt.0 .or. index(lastrcvdmsg,' 73').gt.0) lr73=.true.
+ endif
+ else
+ if(nlasttx.eq.2) lcallingrprt=.true. ! calling with REPORT scenario
+ endif
+ if(lmycall .and. lhiscall) then
+ if(index(lastrcvdmsg,' +').gt.0 .or. index(lastrcvdmsg,' -').gt.0) lastreport=.true.
+ if(index(lastrcvdmsg,' R+').gt.0 .or. index(lastrcvdmsg,' R-').gt.0) lastrrprt=.true.
+ endif
+ if(lastrxmsg(1)%lstate .and. lmycall .and. lhiscall .and. .not.lastreport .and. .not. lastrrprt .and. .not.lrrr .and. &
+ .not.lr73) lgrid=.true.
+ if(lastrxmsg(1)%lstate .and. .not.lmycall .and. lhiscall .and. nlasttx.eq.2) lcallingrprt=.true. ! calling with REPORT
+
+ if(lgrid .and. index(msg(53),trim(mycall)//' '//trim(hiscall)//' AA00').eq.1) then ! standard callsigns
+ i3=-1; n3=-1
+ msg(53)=lastrxmsg(1)%lastmsg
+ call genft8sdvar(msg(53),i3,n3,msgsent37,msgbits,itone)
+ idtone56(53,1:29)=itone(8:36)
+ idtone56(53,30:58)=itone(44:72)
+ itone56(53,1:79)=itone(1:79)
+ endif
+
+ do i=1,58
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+
+ nmycall1=0; nbase1=0
+ do k=1,19
+ if(idtone56(1,k).eq.itonedem(k)) then; if(k.lt.10) nmycall1=nmycall1+1; nbase1=nbase1+1; endif
+ enddo
+
+! /'-01 ','-02 ','-03 ','-04 ','-05 ','-06 ','-07 ','-08 ','-09 ','-10 ',
+! '-11 ','-12 ','-13 ','-14 ','-15 ','-16 ','-17 ','-18 ','-19 ','-20 ',
+! '-21 ','-22 ','-23 ','-24 ','-25 ','-26 ','R-01','R-02','R-03','R-04',
+! 'R-05','R-06','R-07','R-08','R-09','R-10','R-11','R-12','R-13','R-14',
+! 'R-15','R-16','R-17','R-18','R-19','R-20','R-21','R-22','R-23','R-24',
+! 'R-25','R-26','AA00','RRR ','RR73','73 '/
+
+ ilow=1; ihigh=56
+ if(nlasttx.eq.1) then; ilow=1; ihigh=26 ! GRID R+REPORT RRR RR73 73 are not valid msgs
+ elseif(lgrid) then; ilow=27; ihigh=53 ! REPORT RRR RR73 73 are not valid msgs
+ elseif(lcallingrprt) then; ilow=27; ihigh=52 ! GRID REPORT RRR RR73 73 are not valid msgs
+ elseif(lastrrprt) then; ilow=27; ihigh=56 ! REPORT is not a valid msg, GRID shall be excluded later
+ elseif(lr73 .or. lrrr) then; ilow=54; ihigh=56 ! GRID, REPORT or R+REPORT is not a valid msg,
+! MF GRID shall be excluded later
+ endif
+
+ nmatchditer1=0; ncrcpatyiter1=0; imax=0
+ do i=ilow,ihigh
+ if(lastreport .and. i.gt.26 .and. i.lt.54) cycle ! RREPORT is not a valid msg, direction change is not allowed
+ nmatch1=0; ncrcpaty1=0
+ do k=1,58
+ if(idtone56(i,k).eq.itonedem(k)) then; nmatch1=nmatch1+1; if(k.gt.25) ncrcpaty1=ncrcpaty1+1; endif
+ enddo
+ if(nmatch1.gt.nmatchditer1) then
+ imax=i; nmatchditer1=nmatch1; ncrcpatyiter1=ncrcpaty1
+ endif
+ enddo
+!write (*,"(i2,1x,i2,1x,i2,1x,i2)") nmatchlast1,nmatchditer1,ncrcpatylast1,ncrcpatyiter1
+ if(imax.eq.0) return
+ if(srr.gt.3.0 .and. (nmycall1.lt.5 .or. nbase1.lt.10)) return ! prevent false decodes from the strong signals
+ if((nlasttx.eq.1 .or. lcallingrprt) .and. nmycall1.eq.0) return ! answer to other operator
+ if(lr73 .and. (imax.eq.53 .or. imax.eq.54)) return ! RRR,GRID is not a valid msg
+
+ nmatch1=nmatchditer1; ncrcpaty1=ncrcpatyiter1
+ idtone(1:58)=idtone56(imax,1:58)
+ do k=1,58
+ if(idtone(k).eq.itonedem(k)) lmatched(k)=.true.
+ enddo
+
+ if(ncrcpaty1.lt.8) return
+
+ thresh=0.0; i1=0; i2=0; i33=0; i4=0
+ do i=1,58; if(i.le.29) then; s8d(0:7,i)=s8(0:7,i+7); else; s8d(0:7,i)=s8(0:7,i+14); endif; enddo
+ do j=1,58
+ s1=-1.0E6; s2=-1.0E6; s3=-1.0E6; s4=-1.0E6
+ do i=0,7; if(s8d(i,j).gt.s1) then; s1=s8d(i,j); i1=i; endif; enddo
+ do i=0,7; if(i.ne.i1 .and. s8d(i,j).gt.s2) then; s2=s8d(i,j); i2=i; endif; enddo
+ do i=0,7; if(i.ne.i1 .and. i.ne.i2 .and. s8d(i,j).gt.s3) then; s3=s8d(i,j); i33=i; endif; enddo
+ do i=0,7; if(i.ne.i1 .and. i.ne.i2 .and. i.ne.i33 .and. s8d(i,j).gt.s4) then; s4=s8d(i,j); i4=i; endif; enddo
+ mrs(j)=i1; mrs2(j)=i2; mrs3(j)=i33; mrs4(j)=i4
+ enddo
+ ref0=0.; ref0paty=0.; ref0mycl=0.; ref0oth=0.
+ do i=1,58
+ ref0=ref0 + s8d(mrs(i),i)
+ if(i.gt.26) then; ref0paty=ref0paty + s8d(mrs(i),i)
+ else if(i.lt.10) then; ref0mycl=ref0mycl + s8d(mrs(i),i)
+ endif
+ enddo
+ ref0oth=ref0mycl+ref0paty
+ ipk=0; u1=0.; u2=0.; u1paty=0.; u2paty=0.; u1oth=0.; u2oth=0.
+ do k=ilow,ihigh
+ if(lastreport .and. k.gt.26 .and. k.lt.54) cycle ! GRID, RREPORT is not a valid msg, direction change is not allowed
+ psum=0.0; ref=ref0; psumpaty=0.; refpaty=ref0paty; psumoth=0.; refoth=ref0oth
+ do j=1,58; i=idtone56(k,j); psum=psum + s8d(i,j)
+ if(j.gt.26) then; psumpaty=psumpaty + s8d(i,j); psumoth=psumoth + s8d(i,j)
+ else if(j.lt.10) then; psumoth=psumoth + s8d(i,j)
+ endif
+ if(i.eq.mrs(j)) then
+ stmp=s8d(mrs2(j),j)-s8d(i,j); ref=ref + stmp
+ if(j.gt.26) then; refpaty=refpaty + stmp; refoth=refoth + stmp
+ else if(j.lt.10) then; refoth=refoth + stmp
+ endif
+ endif
+ if(i.eq.mrs2(j)) then
+ stmp=s8d(mrs3(j),j) - s8d(mrs2(j),j); ref=ref + stmp
+ if(j.gt.26) then; refpaty=refpaty + stmp; refoth=refoth + stmp
+ else if(j.lt.10) then; refoth=refoth + stmp
+ endif
+ endif
+ if(i.eq.mrs3(j)) then
+ stmp=s8d(mrs4(j),j) - s8d(mrs3(j),j); ref=ref + stmp
+ if(j.gt.26) then; refpaty=refpaty + stmp; refoth=refoth + stmp
+ else if(j.lt.10) then; refoth=refoth + stmp
+ endif
+ endif
+!! if(i.eq.mrs2(j)) then; ref=ref - s8d(mrs(j),j) + s8d(mrs3(j),j); endif
+!! if(i.eq.mrs3(j)) then; ref=ref - s8d(mrs(j),j) + s8d(mrs4(j),j); endif
+ enddo
+ p=psum/ref; ppaty=psumpaty/refpaty; poth=psumoth/refoth
+ if(p.gt.u1) then; u2=u1; u1=p; u2paty=u1paty; u1paty=ppaty; u2oth=u1oth; u1oth=poth; ipk=k
+ else if(p.gt.u2) then; u2=p; u2paty=ppaty; u2oth=poth
+ endif
+ enddo
+ if(lastrrprt .and. ipk.eq.53) return ! GRID is not valid
+ if(lr73 .and. ipk.lt.55) return
+
+ if(lcallingrprt .or. nlasttx.eq.1) nft8rxfslow=1
+
+ if(ipk.ne.0) then
+ qual=100.0*(u1-u2); qualp=100.0*(u1paty-u2paty); qualo=100.0*(u1oth-u2oth)
+ thresh=(qual+10.0)*(u1-0.6); if(thresh.lt.1.5) return
+ threshp=(qualp+10.0)*(u1paty-0.6); thresho=(qualo+10.0)*(u1oth-0.6)
+ if((lcallingrprt .or. nlasttx.eq.1) .and. thresho.lt.3.43) return
+ if(thresho.lt.2.63 .or. threshp.lt.2.45) return
+ if(((nft8rxfslow.eq.1 .and. thresh.gt.4.0) .or. (nft8rxfslow.eq.2 .and. thresh.gt.3.55) &
+ .or. (nft8rxfslow.eq.3 .and. thresh.gt.3.0)) .and. qual.gt.2.6 .and. u1.gt.0.77) then
+!if(ipk.ne.7) print *,'match1',thresh
+ lft8s=.true.; msg37=msg(ipk); itone(1:79)=itone56(ipk,1:79); go to 2
+ endif
+ endif
+
+ if(imax.eq.ipk .and. (nft8rxfslow.gt.1 .or. (nft8rxfslow.eq.1 .and. thresh.gt.2.7)) .and. srr.lt.7.0 &
+ .and. (ncrcpaty1.gt.14 .or. (nmatch1.gt.22 .and. ncrcpaty1.gt.13))) then
+!if(imax.ne.7) print *,'11',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ if(imax.eq.ipk .and. nmatch1.gt.ntresh1 .and. ncrcpaty1.gt.10) then
+!if(imax.ne.7) print *,'12',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ if(nmatchditer1.ge.16) then
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch2=nmatch1; ncrcpaty2=ncrcpaty1
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch2=nmatch2+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty2=ncrcpaty2+1; endif
+ enddo
+ if(nmatch2.gt.ntresh2 .and. ncrcpaty2.gt.19) then
+!if(imax.ne.7) print *,'2',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ if(srr.gt.7.0) return ! do not process strong signals anymore
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch3=nmatch2; ncrcpaty3=ncrcpaty2
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch3=nmatch3+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty3=ncrcpaty3+1; endif
+ enddo
+ if(nmatch3.gt.44 .and. ncrcpaty3.gt.21) then
+!if(imax.ne.7) print *,'3',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch4=nmatch3; ncrcpaty4=ncrcpaty3
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch4=nmatch4+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty4=ncrcpaty4+1; endif
+ enddo
+ if((nft8rxfslow.eq.3 .or. (nft8rxfslow.eq.2 .and. thresh.gt.2.2)) .and. nmatch4.gt.47 .and. ncrcpaty4.gt.23) then
+!if(imax.ne.7) print *,'4',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch5=nmatch4; ncrcpaty5=ncrcpaty4
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch5=nmatch5+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty5=ncrcpaty5+1; endif
+ enddo
+ if((nft8rxfslow.eq.3 .or. (nft8rxfslow.eq.1 .and. thresh.gt.3.4) .or. (nft8rxfslow.eq.2 .and. thresh.gt.3.25)) &
+ .and. nmatch5.gt.50 .and. (nmatch1.gt.21 .or. nmatch2.gt.31 .or. nmatch3.gt.38 .or. nmatch4.gt.46) &
+ .and. ncrcpaty5.gt.25) then
+!if(imax.ne.7) print *,'5',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ do i=1,58
+ if(lmatched(i)) cycle
+ if(i.le.29) then; ip1=maxloc(s8_1(:,i+7))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+7)=0.0
+ else; ip1=maxloc(s8_1(:,i+14))-1; itonedem(i)=ip1(1); s8_1(ip1(1),i+14)=0.0; endif
+ enddo
+ nmatch6=nmatch5; ncrcpaty6=ncrcpaty5
+ do k=1,58
+ if(lmatched(k)) cycle
+ if(idtone(k).eq.itonedem(k)) then; nmatch6=nmatch6+1; lmatched(k)=.true.; if(k.gt.25) ncrcpaty6=ncrcpaty6+1; endif
+ enddo
+ if(((nft8rxfslow.eq.2 .and. thresh.gt.2.6) .or. (nft8rxfslow.eq.3 .and. thresh.gt.2.22)) &
+ .and. imax.eq.ipk .and. ncrcpaty6.gt.26) then
+!if(imax.ne.7) print *,'61',thresh
+!print *,'61',thresh
+!write (*,"(i2,1x,i2,1x,f5.2)") 6,ncrcpaty6,thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+
+ if(nft8rxfslow.eq.1) then
+ if(nmatch6.gt.54 .and. (nmatch1.gt.22 .or. nmatch2.gt.27 .or. nmatch3.gt.35 .or. &
+ (nmatch2-nmatch1).gt.9 .or. (nmatch3-nmatch2).gt.10) .and. ncrcpaty6.gt.29 .and. thresh.gt.3.15) then
+!if(imax.ne.7) print *,'62',thresh
+!print *,'62',thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+ endif
+
+ if(ncrcpaty6.gt.29) then
+ if((nft8rxfslow.eq.3 .or. (nft8rxfslow.eq.3 .and. thresh.gt.1.94)) .and. imax.eq.ipk .and. ncrcpaty2-ncrcpaty1.gt.3 &
+ .and. ncrcpaty3-ncrcpaty2.gt.3 .and. ncrcpaty4-ncrcpaty3.gt.3 .and. ncrcpaty6-ncrcpaty5.lt.6) then
+!if(imax.ne.7) print *,'63',thresh
+!print *,'63',thresh
+!if(imax.ne.7) write (*,"(i2,1x,f5.2,1x,f5.2,1x,f5.2)") 62,u1,qual,thresh
+ lft8s=.true.; msg37=msg(imax); itone(1:79)=itone56(imax,1:79); go to 2
+ endif
+ endif
+ endif
+
+2 if(lft8s) then
+ snr=0.0; snrbase=0.0; snrpaty=0.0; snrdata=0.0; snrsync=0.0; snrmycall=0.0; snrother=0.0
+ do i=1,79
+ xsig=s8(itone(i),i); xnoi=(sum(s8(0:7,i)) - xsig)/7.0; snr1=xsig/(xnoi+1E-6); snr=snr+snr1
+ if(i.gt.7 .and. i.lt.34) then; snrbase=snrbase + snr1; if(i.lt.17) snrmycall=snrmycall + snr1; endif
+ if((i.gt.43 .and. i.lt.73) .or. (i.gt.33 .and. i.lt.37)) then; snrpaty=snrpaty+snr1; endif
+ enddo
+ snrdata=snrbase+snrpaty; snrsync=snr-snrdata; snrother=snrmycall+snrpaty
+ snrsync=snrsync/21.0; snrother=snrother/48.0; snrpaty=snrpaty/32.0
+ if(lcallingrprt .or. nlasttx.eq.1) then
+ soratio=snrsync/snrother
+ if(soratio.gt.1.29) then;lft8s=.false.; msg37=''; return; endif
+ endif
+ spratio=snrsync/snrpaty
+ if(spratio.lt.0.6 .or. spratio.gt.1.25) then;lft8s=.false.; msg37=''; return; endif
+
+ do i=1,7; xsync(i)=s8(itone(i),i); enddo; do i=8,14; k=i+29; xsync(i)=s8(itone(k),k); enddo
+ do i=15,21; k=i+58; xsync(i)=s8(itone(k),k); enddo
+ do i=1,29; k=i+7; xdata(i)=s8(itone(k),k); enddo; do i=30,58; k=i+14; xdata(i)=s8(itone(k),k); enddo
+ do i=1,79; k=modulo(itone(i)+4,8); xnoise(i)=s8(k,i); enddo
+
+ do i=1,19
+ if((xsync(i).gt.xsync(i+1) .and. xsync(i).lt.xsync(i+2)) &
+ .or. (xsync(i).lt.xsync(i+1) .and. xsync(i).gt.xsync(i+2))) then; xmsync(i)=xsync(i)
+ else if((xsync(i+1).gt.xsync(i) .and. xsync(i+1).lt.xsync(i+2)) &
+ .or. (xsync(i+1).lt.xsync(i) .and. xsync(i+1).gt.xsync(i+2))) then; xmsync(i)=xsync(i+1)
+ else if((xsync(i+2).gt.xsync(i) .and. xsync(i+2).lt.xsync(i+1)) &
+ .or. (xsync(i+2).lt.xsync(i) .and. xsync(i+2).gt.xsync(i+1))) then; xmsync(i)=xsync(i+2)
+ else; xmsync(i)=xsync(i)
+ endif
+ enddo
+ xmsync(20)=xmsync(18); xmsync(21)=xmsync(19)
+
+ do i=1,56
+ if((xdata(i).gt.xdata(i+1) .and. xdata(i).lt.xdata(i+2)) &
+ .or. (xdata(i).lt.xdata(i+1) .and. xdata(i).gt.xdata(i+2))) then; xmdata(i)=xdata(i)
+ else if((xdata(i+1).gt.xdata(i) .and. xdata(i+1).lt.xdata(i+2)) &
+ .or. (xdata(i+1).lt.xdata(i) .and. xdata(i+1).gt.xdata(i+2))) then; xmdata(i)=xdata(i+1)
+ else if((xdata(i+2).gt.xdata(i) .and. xdata(i+2).lt.xdata(i+1)) &
+ .or. (xdata(i+2).lt.xdata(i) .and. xdata(i+2).gt.xdata(i+1))) then; xmdata(i)=xdata(i+2)
+ else; xmdata(i)=xdata(i)
+ endif
+ enddo
+ xmdata(57)=xmdata(55); xmdata(58)=xmdata(56)
+
+ do i=1,77
+ if((xnoise(i).gt.xnoise(i+1) .and. xnoise(i).lt.xnoise(i+2)) &
+ .or. (xnoise(i).lt.xnoise(i+1) .and. xnoise(i).gt.xnoise(i+2))) then; xmnoise(i)=xnoise(i)
+ else if((xnoise(i+1).gt.xnoise(i) .and. xnoise(i+1).lt.xnoise(i+2)) &
+ .or. (xnoise(i+1).lt.xnoise(i) .and. xnoise(i+1).gt.xnoise(i+2))) then; xmnoise(i)=xnoise(i+1)
+ else if((xnoise(i+2).gt.xnoise(i) .and. xnoise(i+2).lt.xnoise(i+1)) &
+ .or. (xnoise(i+2).lt.xnoise(i) .and. xnoise(i+2).gt.xnoise(i+1))) then; xmnoise(i)=xnoise(i+2)
+ else; xmnoise(i)=xnoise(i)
+ endif
+ enddo
+ xmnoise(78)=xmnoise(76); xmnoise(79)=xmnoise(77)
+
+ ssync=sum(xmsync)/21.0; spaty=sum(xmdata(27:58))/32.0; spnoise=(sum(xmnoise(34:36)) + sum(xmnoise(44:72)))/32.0
+ spother=(sum(xmdata(1:9)) + sum(xmdata(27:58)))/41.0
+ spratiom=ssync/(spaty+1E-6); spnratiom=spaty/(spnoise+1E-6); sporatiom=ssync/(spother+1E-6)
+ if(spnratiom.gt.2.3) then
+ if(lcallingrprt .or. nlasttx.eq.1) then; if(sporatiom.gt.1.35) then; lft8s=.false.; msg37=''; return; endif
+ else; if(spratiom.gt.1.35) then; lft8s=.false.; msg37=''; return; endif
+ endif
+ endif
+ endif
+
+ return
+end subroutine ft8svar
diff --git a/lib/ft8var/gen_ft8wavevar.f90 b/lib/ft8var/gen_ft8wavevar.f90 new file mode 100755 index 00000000..a7dac56e --- /dev/null +++ b/lib/ft8var/gen_ft8wavevar.f90 @@ -0,0 +1,79 @@ +subroutine gen_ft8wavevar(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave)
+!
+! generate ft8 waveform using Gaussian-filtered frequency pulses.
+!
+ parameter(MAX_SECONDS=20,NTAB=65536)
+ real wave(nwave)
+ complex cwave(nwave),ctab(0:NTAB-1)
+ real pulse(23040)
+ real dphi(0:(nsym+2)*nsps-1)
+ integer itone(nsym)
+ data ibt0/0/
+ save pulse,twopi,dt,hmod,ibt0,ctab
+
+ ibt=nint(10*bt)
+ if(ibt0.ne.ibt) then
+ twopi=8.0*atan(1.0)
+ dt=1.0/fsample
+ hmod=1.0
+! Compute the frequency-smoothing pulse
+ do i=1,3*nsps
+ tt=(i-1.5*nsps)/real(nsps)
+ pulse(i)=gfsk_pulse(bt,tt)
+ enddo
+ ibt0=nint(10*bt)
+ do i=0,NTAB-1
+ phi=i*twopi/NTAB
+ ctab(i)=cmplx(cos(phi),sin(phi))
+ enddo
+ endif
+
+! Compute the smoothed frequency waveform.
+! Length = (nsym+2)*nsps samples, first and last symbols extended
+ dphi_peak=twopi*hmod/real(nsps)
+ dphi=0.0
+ do j=1,nsym
+ ib=(j-1)*nsps
+ ie=ib+3*nsps-1
+ dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j)
+ enddo
+! Add dummy symbols at beginning and end with tone values equal to 1st and last symbol, respectively
+ dphi(0:2*nsps-1)=dphi(0:2*nsps-1)+dphi_peak*itone(1)*pulse(nsps+1:3*nsps)
+ dphi(nsym*nsps:(nsym+2)*nsps-1)=dphi(nsym*nsps:(nsym+2)*nsps-1)+dphi_peak*itone(nsym)*pulse(1:2*nsps)
+
+! Calculate and insert the audio waveform
+ phi=0.0
+ dphi = dphi + twopi*f0*dt !Shift frequency up by f0
+ if(icmplx .eq. 0) wave=0.
+ if(icmplx .ne. 0) cwave=0. !Avoid writing to memory we may not have access to
+
+ k=0
+ do j=nsps,nsps+nwave-1 !Don't include dummy symbols
+ k=k+1
+ if(icmplx.eq.0) then
+ wave(k)=sin(phi)
+ else
+ i=phi*float(NTAB)/twopi
+ cwave(k)=ctab(i)
+ endif
+ phi=mod(phi+dphi(j),twopi)
+ enddo
+
+! Apply envelope shaping to the first and last symbols
+ nramp=nint(nsps/8.0)
+ if(icmplx.eq.0) then
+ wave(1:nramp)=wave(1:nramp) * &
+ (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ k1=nsym*nsps-nramp+1
+ wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * &
+ (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ else
+ cwave(1:nramp)=cwave(1:nramp) * &
+ (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ k1=nsym*nsps-nramp+1
+ cwave(k1:k1+nramp-1)=cwave(k1:k1+nramp-1) * &
+ (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ endif
+
+ return
+end subroutine gen_ft8wavevar
diff --git a/lib/ft8var/genft8sdvar.f90 b/lib/ft8var/genft8sdvar.f90 new file mode 100755 index 00000000..fb33b4a3 --- /dev/null +++ b/lib/ft8var/genft8sdvar.f90 @@ -0,0 +1,38 @@ +
+subroutine genft8sdvar(msg,i3,n3,msgsent,msgbits,itone)
+
+! Encode an FT8 message, producing array itone().
+
+ use packjt77sdvar
+ use ft8_mod1, only : icos7,graymap
+ character msg*37,msgsent*37,c77*77
+ integer*1 msgbits(77),codeword(174)
+ integer itone(79)
+ logical unpk77_success
+
+ i3=-1
+ n3=-1
+ call pack77sdvar(msg,i3,n3,c77)
+ call unpack77sdvar(c77,msgsent,unpk77_success)
+ read(c77,'(77i1)',err=1) msgbits
+ if(unpk77_success) go to 2
+1 msgbits=0
+ itone=0
+ msgsent='*** bad message *** '
+ go to 900
+
+2 call encode174_91var(msgbits,codeword) !Encode the test message
+
+! Message structure: S7 D29 S7 D29 S7
+ itone(1:7)=icos7; itone(37:43)=icos7; itone(73:79)=icos7
+ k=7
+ do j=1,58
+ i=3*j -2
+ k=k+1
+ if(j.eq.30) k=k+7
+ indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2)
+ itone(k)=graymap(indx)
+ enddo
+
+900 return
+end subroutine genft8sdvar
diff --git a/lib/ft8var/genft8var.f90 b/lib/ft8var/genft8var.f90 new file mode 100755 index 00000000..defc879e --- /dev/null +++ b/lib/ft8var/genft8var.f90 @@ -0,0 +1,43 @@ +subroutine genft8var(msg,i3,n3,ntxhash,msgsent,msgbits,itone)
+
+! Encode an FT8 message, producing array itone().
+
+ use packjt77var
+ use ft8_mod1, only : icos7,graymap
+ character msg*37,msgsent*37,c77*77
+ integer*1 msgbits(77),codeword(174)
+ integer itone(79)
+ logical unpk77_success
+
+ i3=-1
+ n3=-1
+ call pack77var(msg,i3,n3,c77,ntxhash)
+ if(ntxhash.eq.1) then
+ call unpack77var(c77,0,msgsent,unpk77_success,26) !TX message, unpack to get msgsent, use TX hash tables and do not save RX hash values
+ else
+ call unpack77var(c77,0,msgsent,unpk77_success,27) !service message, unpack to get msgsent. Do not save hash values
+ endif
+ read(c77,'(77i1)',err=1) msgbits
+ if(unpk77_success) go to 2
+1 msgbits=0
+ itone=0
+ msgsent='*** bad message *** '
+ go to 900
+
+entry get_tones_from_77bits(msgbits,itone)
+
+2 call encode174_91var(msgbits,codeword) !Encode the test message
+
+! Message structure: S7 D29 S7 D29 S7
+ itone(1:7)=icos7; itone(37:43)=icos7; itone(73:79)=icos7
+ k=7
+ do j=1,58
+ i=3*j -2
+ k=k+1
+ if(j.eq.30) k=k+7
+ indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2)
+ itone(k)=graymap(indx)
+ enddo
+
+900 return
+end subroutine genft8var
diff --git a/lib/ft8var/jt65_mod2var.f90 b/lib/ft8var/jt65_mod2var.f90 new file mode 100755 index 00000000..459f0290 --- /dev/null +++ b/lib/ft8var/jt65_mod2var.f90 @@ -0,0 +1,7 @@ +
+module jt65_mod2var
+
+ real s3(64,63),s3a(64,63)
+ integer correct(63),correct_hint(63)
+
+end module jt65_mod2var
\ No newline at end of file diff --git a/lib/ft8var/jt65_mod5.f90 b/lib/ft8var/jt65_mod5.f90 new file mode 100755 index 00000000..accef1b0 --- /dev/null +++ b/lib/ft8var/jt65_mod5.f90 @@ -0,0 +1,6 @@ +
+module jt65_mod5
+
+ real, save :: ref(3413)
+
+end module jt65_mod5
\ No newline at end of file diff --git a/lib/ft8var/jt65_mod9.f90 b/lib/ft8var/jt65_mod9.f90 new file mode 100755 index 00000000..22ca14ac --- /dev/null +++ b/lib/ft8var/jt65_mod9.f90 @@ -0,0 +1,19 @@ +module jt65_mod9
+! stores callsign DB in memory for false decodes checking
+
+ parameter (MAXC=200000)
+! supporting 7-char Australian callsigns
+ character*7 call0c(11500),calld(11100),callef(9000),callgh(7500),calli(7600),callj(10000),callk(24000),calllm(6500), &
+ calln(9400),callo(6700),callpq(5800),callr(6500),callst(7500),calluv(10400),callw(13700),callxz(5800)
+ character callsign*12
+ character*180 line
+ integer ncall0c,ncalld,ncallef,ncallgh,ncalli,ncallj,ncallk,ncalllm,ncalln,ncallo,ncallpq,ncallr,ncallst,ncalluv, &
+ ncallw,ncallxz
+ logical ldbvalid
+ data ldbvalid/.true./
+ data ncall0c,ncalld,ncallef,ncallgh,ncalli,ncallj,ncallk,ncalllm,ncalln,ncallo,ncallpq,ncallr,ncallst,ncalluv,ncallw, &
+ ncallxz/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0/
+
+end module jt65_mod9
+
+!callj dim was 9000; increased 20250709 to accommodate size of new ALLCALL7.TXT file dated 20250619
diff --git a/lib/ft8var/ldpc_174_91_c_reordered_parity.f90 b/lib/ft8var/ldpc_174_91_c_reordered_parity.f90 new file mode 100755 index 00000000..135c9de9 --- /dev/null +++ b/lib/ft8var/ldpc_174_91_c_reordered_parity.f90 @@ -0,0 +1,270 @@ +data Mn/ &
+ 16, 45, 73, &
+ 25, 51, 62, &
+ 33, 58, 78, &
+ 1, 44, 45, &
+ 2, 7, 61, &
+ 3, 6, 54, &
+ 4, 35, 48, &
+ 5, 13, 21, &
+ 8, 56, 79, &
+ 9, 64, 69, &
+ 10, 19, 66, &
+ 11, 36, 60, &
+ 12, 37, 58, &
+ 14, 32, 43, &
+ 15, 63, 80, &
+ 17, 28, 77, &
+ 18, 74, 83, &
+ 22, 53, 81, &
+ 23, 30, 34, &
+ 24, 31, 40, &
+ 26, 41, 76, &
+ 27, 57, 70, &
+ 29, 49, 65, &
+ 3, 38, 78, &
+ 5, 39, 82, &
+ 46, 50, 73, &
+ 51, 52, 74, &
+ 55, 71, 72, &
+ 44, 67, 72, &
+ 43, 68, 78, &
+ 1, 32, 59, &
+ 2, 6, 71, &
+ 4, 16, 54, &
+ 7, 65, 67, &
+ 8, 30, 42, &
+ 9, 22, 31, &
+ 10, 18, 76, &
+ 11, 23, 82, &
+ 12, 28, 61, &
+ 13, 52, 79, &
+ 14, 50, 51, &
+ 15, 81, 83, &
+ 17, 29, 60, &
+ 19, 33, 64, &
+ 20, 26, 73, &
+ 21, 34, 40, &
+ 24, 27, 77, &
+ 25, 55, 58, &
+ 35, 53, 66, &
+ 36, 48, 68, &
+ 37, 46, 75, &
+ 38, 45, 47, &
+ 39, 57, 69, &
+ 41, 56, 62, &
+ 20, 49, 53, &
+ 46, 52, 63, &
+ 45, 70, 75, &
+ 27, 35, 80, &
+ 1, 15, 30, &
+ 2, 68, 80, &
+ 3, 36, 51, &
+ 4, 28, 51, &
+ 5, 31, 56, &
+ 6, 20, 37, &
+ 7, 40, 82, &
+ 8, 60, 69, &
+ 9, 10, 49, &
+ 11, 44, 57, &
+ 12, 39, 59, &
+ 13, 24, 55, &
+ 14, 21, 65, &
+ 16, 71, 78, &
+ 17, 30, 76, &
+ 18, 25, 80, &
+ 19, 61, 83, &
+ 22, 38, 77, &
+ 23, 41, 50, &
+ 7, 26, 58, &
+ 29, 32, 81, &
+ 33, 40, 73, &
+ 18, 34, 48, &
+ 13, 42, 64, &
+ 5, 26, 43, &
+ 47, 69, 72, &
+ 54, 55, 70, &
+ 45, 62, 68, &
+ 10, 63, 67, &
+ 14, 66, 72, &
+ 22, 60, 74, &
+ 35, 39, 79, &
+ 1, 46, 64, &
+ 1, 24, 66, &
+ 2, 5, 70, &
+ 3, 31, 65, &
+ 4, 49, 58, &
+ 1, 4, 5, &
+ 6, 60, 67, &
+ 7, 32, 75, &
+ 8, 48, 82, &
+ 9, 35, 41, &
+ 10, 39, 62, &
+ 11, 14, 61, &
+ 12, 71, 74, &
+ 13, 23, 78, &
+ 11, 35, 55, &
+ 15, 16, 79, &
+ 7, 9, 16, &
+ 17, 54, 63, &
+ 18, 50, 57, &
+ 19, 30, 47, &
+ 20, 64, 80, &
+ 21, 28, 69, &
+ 22, 25, 43, &
+ 13, 22, 37, &
+ 2, 47, 51, &
+ 23, 54, 74, &
+ 26, 34, 72, &
+ 27, 36, 37, &
+ 21, 36, 63, &
+ 29, 40, 44, &
+ 19, 26, 57, &
+ 3, 46, 82, &
+ 14, 15, 58, &
+ 33, 52, 53, &
+ 30, 43, 52, &
+ 6, 9, 52, &
+ 27, 33, 65, &
+ 25, 69, 73, &
+ 38, 55, 83, &
+ 20, 39, 77, &
+ 18, 29, 56, &
+ 32, 48, 71, &
+ 42, 51, 59, &
+ 28, 44, 79, &
+ 34, 60, 62, &
+ 31, 45, 61, &
+ 46, 68, 77, &
+ 6, 24, 76, &
+ 8, 10, 78, &
+ 40, 41, 70, &
+ 17, 50, 53, &
+ 42, 66, 68, &
+ 4, 22, 72, &
+ 36, 64, 81, &
+ 13, 29, 47, &
+ 2, 8, 81, &
+ 56, 67, 73, &
+ 5, 38, 50, &
+ 12, 38, 64, &
+ 59, 72, 80, &
+ 3, 26, 79, &
+ 45, 76, 81, &
+ 1, 65, 74, &
+ 7, 18, 77, &
+ 11, 56, 59, &
+ 14, 39, 54, &
+ 16, 37, 66, &
+ 10, 28, 55, &
+ 15, 60, 70, &
+ 17, 25, 82, &
+ 20, 30, 31, &
+ 12, 67, 68, &
+ 23, 75, 80, &
+ 27, 32, 62, &
+ 24, 69, 75, &
+ 19, 21, 71, &
+ 34, 53, 61, &
+ 35, 46, 47, &
+ 33, 59, 76, &
+ 40, 43, 83, &
+ 41, 42, 63, &
+ 49, 75, 83, &
+ 20, 44, 48, &
+ 42, 49, 57/
+
+data Nm/ &
+ 4, 31, 59, 91, 92, 96, 153, &
+ 5, 32, 60, 93, 115, 146, 0, &
+ 6, 24, 61, 94, 122, 151, 0, &
+ 7, 33, 62, 95, 96, 143, 0, &
+ 8, 25, 63, 83, 93, 96, 148, &
+ 6, 32, 64, 97, 126, 138, 0, &
+ 5, 34, 65, 78, 98, 107, 154, &
+ 9, 35, 66, 99, 139, 146, 0, &
+ 10, 36, 67, 100, 107, 126, 0, &
+ 11, 37, 67, 87, 101, 139, 158, &
+ 12, 38, 68, 102, 105, 155, 0, &
+ 13, 39, 69, 103, 149, 162, 0, &
+ 8, 40, 70, 82, 104, 114, 145, &
+ 14, 41, 71, 88, 102, 123, 156, &
+ 15, 42, 59, 106, 123, 159, 0, &
+ 1, 33, 72, 106, 107, 157, 0, &
+ 16, 43, 73, 108, 141, 160, 0, &
+ 17, 37, 74, 81, 109, 131, 154, &
+ 11, 44, 75, 110, 121, 166, 0, &
+ 45, 55, 64, 111, 130, 161, 173, &
+ 8, 46, 71, 112, 119, 166, 0, &
+ 18, 36, 76, 89, 113, 114, 143, &
+ 19, 38, 77, 104, 116, 163, 0, &
+ 20, 47, 70, 92, 138, 165, 0, &
+ 2, 48, 74, 113, 128, 160, 0, &
+ 21, 45, 78, 83, 117, 121, 151, &
+ 22, 47, 58, 118, 127, 164, 0, &
+ 16, 39, 62, 112, 134, 158, 0, &
+ 23, 43, 79, 120, 131, 145, 0, &
+ 19, 35, 59, 73, 110, 125, 161, &
+ 20, 36, 63, 94, 136, 161, 0, &
+ 14, 31, 79, 98, 132, 164, 0, &
+ 3, 44, 80, 124, 127, 169, 0, &
+ 19, 46, 81, 117, 135, 167, 0, &
+ 7, 49, 58, 90, 100, 105, 168, &
+ 12, 50, 61, 118, 119, 144, 0, &
+ 13, 51, 64, 114, 118, 157, 0, &
+ 24, 52, 76, 129, 148, 149, 0, &
+ 25, 53, 69, 90, 101, 130, 156, &
+ 20, 46, 65, 80, 120, 140, 170, &
+ 21, 54, 77, 100, 140, 171, 0, &
+ 35, 82, 133, 142, 171, 174, 0, &
+ 14, 30, 83, 113, 125, 170, 0, &
+ 4, 29, 68, 120, 134, 173, 0, &
+ 1, 4, 52, 57, 86, 136, 152, &
+ 26, 51, 56, 91, 122, 137, 168, &
+ 52, 84, 110, 115, 145, 168, 0, &
+ 7, 50, 81, 99, 132, 173, 0, &
+ 23, 55, 67, 95, 172, 174, 0, &
+ 26, 41, 77, 109, 141, 148, 0, &
+ 2, 27, 41, 61, 62, 115, 133, &
+ 27, 40, 56, 124, 125, 126, 0, &
+ 18, 49, 55, 124, 141, 167, 0, &
+ 6, 33, 85, 108, 116, 156, 0, &
+ 28, 48, 70, 85, 105, 129, 158, &
+ 9, 54, 63, 131, 147, 155, 0, &
+ 22, 53, 68, 109, 121, 174, 0, &
+ 3, 13, 48, 78, 95, 123, 0, &
+ 31, 69, 133, 150, 155, 169, 0, &
+ 12, 43, 66, 89, 97, 135, 159, &
+ 5, 39, 75, 102, 136, 167, 0, &
+ 2, 54, 86, 101, 135, 164, 0, &
+ 15, 56, 87, 108, 119, 171, 0, &
+ 10, 44, 82, 91, 111, 144, 149, &
+ 23, 34, 71, 94, 127, 153, 0, &
+ 11, 49, 88, 92, 142, 157, 0, &
+ 29, 34, 87, 97, 147, 162, 0, &
+ 30, 50, 60, 86, 137, 142, 162, &
+ 10, 53, 66, 84, 112, 128, 165, &
+ 22, 57, 85, 93, 140, 159, 0, &
+ 28, 32, 72, 103, 132, 166, 0, &
+ 28, 29, 84, 88, 117, 143, 150, &
+ 1, 26, 45, 80, 128, 147, 0, &
+ 17, 27, 89, 103, 116, 153, 0, &
+ 51, 57, 98, 163, 165, 172, 0, &
+ 21, 37, 73, 138, 152, 169, 0, &
+ 16, 47, 76, 130, 137, 154, 0, &
+ 3, 24, 30, 72, 104, 139, 0, &
+ 9, 40, 90, 106, 134, 151, 0, &
+ 15, 58, 60, 74, 111, 150, 163, &
+ 18, 42, 79, 144, 146, 152, 0, &
+ 25, 38, 65, 99, 122, 160, 0, &
+ 17, 42, 75, 129, 170, 172, 0/
+
+data nrw/ &
+7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, &
+6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, &
+6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, &
+6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, &
+6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, &
+6,6,6/
+
+ncw=3
diff --git a/lib/ft8var/msgparservar.f90 b/lib/ft8var/msgparservar.f90 new file mode 100755 index 00000000..276047d1 --- /dev/null +++ b/lib/ft8var/msgparservar.f90 @@ -0,0 +1,26 @@ +subroutine msgparservar(msg37,msg37_2)
+
+ character msg37*37,msg37_2*37,call1*12,call2*12,call3*12,report*6
+
+! ES1JA RR73; TA1BM <...> -22
+! ES1JA RR73; TA1BM <SX60RAAG> -22
+
+ call1=' '; call2=' '; call3=' '; report=' '
+ ispc1=index(msg37,' '); ispc2=index(msg37((ispc1+1):),' ')+ispc1
+ ispc3=index(msg37((ispc2+1):),' ')+ispc2; ispc4=index(msg37((ispc3+1):),' ')+ispc3
+ ispc5=index(msg37((ispc4+1):),' ')+ispc4
+ if(ispc5.gt.20) then
+ call1=msg37(1:ispc1-1); call2=msg37(ispc2+1:ispc3-1)
+ if(msg37(ispc3+1:ispc3+2).eq.'<.') then
+ call3='<...>'
+ else
+ call3=msg37(ispc3+1:ispc4-1)
+ endif
+ if(len_trim(call3).lt.11) then; report=msg37(ispc4+1:ispc5-1); else; report=msg37(ispc4+1:37); endif
+! build standard messages
+ msg37=trim(call1)//' RR73; '//trim(call2)//' '//trim(call3)//' '//trim(report) !ft8md reformat msg37
+ msg37_2=trim(call2)//' '//trim(call3)//' '//trim(report)
+ endif
+
+ return
+end subroutine msgparservar
diff --git a/lib/ft8var/osd174_91var.f90 b/lib/ft8var/osd174_91var.f90 new file mode 100755 index 00000000..27cd11bf --- /dev/null +++ b/lib/ft8var/osd174_91var.f90 @@ -0,0 +1,400 @@ +subroutine osd174_91var(llr,apmask,ndeep,message77,cw,nhardmin,dmin,nthr)
+!
+! An ordered-statistics decoder for the (174,91) code.
+!
+use ft8_mod1, only : first_osd,gen
+integer, parameter:: N=174, K=91, M=N-K
+integer*1 apmask(N),apmaskr(N)
+integer*1 genmrb(K,N),g2(N,K)
+integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K)
+integer*1 r2pat(N-K)
+integer indices(N),nxor(N)
+integer*1 cw(N),ce(N),c0(N),hdec(N)
+integer*1 decoded(K)
+integer*1 message77(77)
+integer indx(N)
+real llr(N),rx(N),absrx(N)
+include '/lib/ft8/ldpc_174_91_c_generator.f90'
+logical reset
+
+integer, DIMENSION(:,:), ALLOCATABLE :: indexes
+integer, DIMENSION(:), ALLOCATABLE :: fp
+integer, DIMENSION(:), ALLOCATABLE :: np
+
+interface
+ subroutine boxit91var(indexes,fp,np,reset,e2,ntau,npindex,i1,i2)
+ integer indexes(:,:),fp(0:),np(:),ntau
+ integer*1 e2(1:ntau)
+ integer npindex,i1,i2
+ logical reset
+ end subroutine boxit91var
+ subroutine fetchit91var(indexes,fp,np,reset,e2,ntau,i1,i2,nthr)
+ integer indexes(:,:),fp(0:),np(:),ntau
+ integer*1 e2(1:ntau)
+ integer i1,i2,nthr
+ logical reset
+ end subroutine fetchit91var
+end interface
+
+npre1=0; npre2=0; d1=0.
+if(first_osd) then ! fill the generator matrix
+!$omp critical(first_osd)
+ gen=0
+ do i=1,M
+ do j=1,23
+ read(g(i)(j:j),"(Z1)") istr
+ ibmax=4
+ if(j.eq.23) ibmax=3
+ do jj=1, ibmax
+ irow=(j-1)*4+jj
+ if( btest(istr,4-jj) ) gen(irow,K+i)=1
+ enddo
+ enddo
+ enddo
+ do irow=1,K
+ gen(irow,irow)=1
+ enddo
+first_osd=.false.
+!$omp end critical(first_osd)
+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 mrbencode91var(m0,c0,g2,N,K)
+nxor=ieor(c0,hdec)
+nhardmin=sum(nxor)
+dmin=sum(nxor*absrx)
+
+cw=c0
+ntotal=0
+nrejected=0
+
+if(ndeep.eq.0) goto 998 ! norder=0
+if(ndeep.gt.5) ndeep=5
+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=0
+ nt=40
+ ntheta=12
+ ntau=19
+elseif(ndeep.eq.5) then
+ nord=2
+ 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
+ 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 mrbencode91var(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 mrbencode91var(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 nextpat91var(misub,k,iorder,iflag)
+ enddo
+enddo
+
+if(npre2.eq.1) then
+ allocate(indexes(5000,2), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ allocate(fp(0:525000), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ allocate(np(5000), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ 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 boxit91var(indexes,fp,np,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 mrbencode91var(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 fetchit91var(indexes,fp,np,reset,r2pat(1:ntau),ntau,in1,in2,nthr)
+ 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 mrbencode91var(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 nextpat91var(misub,K,nord,iflag)
+ enddo
+ deallocate (indexes, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ deallocate (fp, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ deallocate (np, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+endif
+
+998 continue
+! Re-order the codeword to [message bits][parity bits] format.
+cw(indices)=cw
+hdec(indices)=hdec
+decoded=cw(1:K)
+call chkcrc14a(decoded,nbadcrc)
+message77=decoded(1:77)
+if(nbadcrc.eq.1) nhardmin=-nhardmin
+
+return
+end subroutine osd174_91var
+
+subroutine mrbencode91var(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 mrbencode91var
+
+subroutine nextpat91var(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 nextpat91var
+
+subroutine boxit91var(indexes,fp,np,reset,e2,ntau,npindex,i1,i2)
+ integer indexes(:,:),fp(0:),np(:)
+ integer*1 e2(1:ntau)
+ logical reset
+
+ 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 boxit91var
+
+subroutine fetchit91var(indexes,fp,np,reset,e2,ntau,i1,i2,nthr)
+ integer indexes(:,:),fp(0:),np(:)
+ integer lastpat(24),inext(24)
+ integer*1 e2(1:ntau)
+ logical reset
+ save lastpat,inext
+
+ if(reset) then
+ lastpat(nthr)=-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(nthr).ne.ipat .and. index.gt.0) then ! return first set of indices
+ i1=indexes(index,1)
+ i2=indexes(index,2)
+ inext(nthr)=np(index)
+ elseif(lastpat(nthr).eq.ipat .and. inext(nthr).gt.0) then
+ i1=indexes(inext(nthr),1)
+ i2=indexes(inext(nthr),2)
+ inext(nthr)=np(inext(nthr))
+ else
+ i1=-1
+ i2=-1
+ inext(nthr)=-1
+ endif
+ lastpat(nthr)=ipat
+
+ return
+end subroutine fetchit91var
\ No newline at end of file diff --git a/lib/ft8var/osd174var.f90 b/lib/ft8var/osd174var.f90 new file mode 100755 index 00000000..2d8257a7 --- /dev/null +++ b/lib/ft8var/osd174var.f90 @@ -0,0 +1,399 @@ +
+subroutine osd174var(llr,apmask,ndeep,decoded,cw,nhardmin,dmin,nthr)
+!
+! An ordered-statistics decoder for the (174,87) code.
+!
+include "ldpc_174_87_params.f90"
+
+integer*1 apmask(N),apmaskr(N)
+integer*1 gen(K,N)
+integer*1 genmrb(K,N),g2(N,K)
+integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K)
+integer*1 r2pat(N-K)
+integer indices(N),nxor(N)
+integer*1 cw(N),ce(N),c0(N),hdec(N)
+integer*1 decoded(K)
+integer indx(N)
+real llr(N),rx(N),absrx(N)
+logical first,reset
+data first/.true./
+
+integer, DIMENSION(:,:), ALLOCATABLE :: indexes
+integer, DIMENSION(:), ALLOCATABLE :: fp
+integer, DIMENSION(:), ALLOCATABLE :: np
+
+interface
+ subroutine boxitvar(indexes,fp,np,reset,e2,ntau,npindex,i1,i2)
+ integer indexes(:,:),fp(0:),np(:),ntau
+ integer*1 e2(1:ntau)
+ integer npindex,i1,i2
+ logical reset
+ end subroutine boxitvar
+ subroutine fetchitvar(indexes,fp,np,reset,e2,ntau,i1,i2,nthr)
+ integer indexes(:,:),fp(0:),np(:),ntau
+ integer*1 e2(1:ntau)
+ integer i1,i2,nthr
+ logical reset
+ end subroutine fetchitvar
+end interface
+
+save first,gen
+
+npre1=0; npre2=0; d1=0.
+
+if( first ) then ! fill the generator matrix
+ gen=0
+ do i=1,M
+ do j=1,22
+ read(g(i)(j:j),"(Z1)") istr
+ do jj=1, 4
+ irow=(j-1)*4+jj
+ if( btest(istr,4-jj) ) gen(irow,i)=1
+ enddo
+ enddo
+ enddo
+ do irow=1,K
+ gen(irow,M+irow)=1
+ enddo
+first=.false.
+endif
+
+! Re-order received vector to place systematic msg bits at the end.
+rx=llr(colorder+1)
+apmaskr=apmask(colorder+1)
+
+! 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 mrbencodevar(m0,c0,g2,N,K)
+nxor=ieor(c0,hdec)
+nhardmin=sum(nxor)
+dmin=sum(nxor*absrx)
+
+cw=c0
+ntotal=0
+nrejected=0
+
+if(ndeep.eq.0) goto 998 ! norder=0
+if(ndeep.gt.5) ndeep=5
+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=0
+ nt=40
+ ntheta=12
+ ntau=19
+elseif(ndeep.eq.5) then
+ nord=2
+ 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
+ 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 mrbencodevar(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 mrbencodevar(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 nextpatvar(misub,k,iorder,iflag)
+ enddo
+enddo
+
+if(npre2.eq.1) then
+ allocate(indexes(4000,2), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ allocate(fp(0:525000), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ allocate(np(4000), STAT = nAllocateStatus1)
+ if (nAllocateStatus1 .ne. 0) STOP "Not enough memory"
+ 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 boxitvar(indexes,fp,np,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 mrbencodevar(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 fetchitvar(indexes,fp,np,reset,r2pat(1:ntau),ntau,in1,in2,nthr)
+ 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 mrbencodevar(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 nextpatvar(misub,K,nord,iflag)
+ enddo
+ deallocate (indexes, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ deallocate (fp, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+ deallocate (np, STAT = nDeAllocateStatus1)
+ if (nDeAllocateStatus1.ne.0) print *, 'failed to release memory'
+endif
+
+998 continue
+! Re-order the codeword to place message bits at the end.
+cw(indices)=cw
+hdec(indices)=hdec
+decoded=cw(M+1:N)
+cw(colorder+1)=cw ! put the codeword back into received-word order
+return
+end subroutine osd174var
+
+subroutine mrbencodevar(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 mrbencodevar
+
+subroutine nextpatvar(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 nextpatvar
+
+subroutine boxitvar(indexes,fp,np,reset,e2,ntau,npindex,i1,i2)
+ integer indexes(:,:),fp(0:),np(:)
+ integer*1 e2(1:ntau)
+ logical reset
+
+ 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 boxitvar
+
+subroutine fetchitvar(indexes,fp,np,reset,e2,ntau,i1,i2,nthr)
+ integer indexes(:,:),fp(0:),np(:)
+ integer lastpat(36),inext(36) ! up to 36 threads in FT8 decoding
+ integer*1 e2(1:ntau)
+ logical reset
+ save lastpat,inext
+
+ if(reset) then
+ lastpat(nthr)=-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(nthr).ne.ipat .and. index.gt.0) then ! return first set of indices
+ i1=indexes(index,1)
+ i2=indexes(index,2)
+ inext(nthr)=np(index)
+ elseif(lastpat(nthr).eq.ipat .and. inext(nthr).gt.0) then
+ i1=indexes(inext(nthr),1)
+ i2=indexes(inext(nthr),2)
+ inext(nthr)=np(inext(nthr))
+ else
+ i1=-1
+ i2=-1
+ inext(nthr)=-1
+ endif
+ lastpat(nthr)=ipat
+
+ return
+end subroutine fetchitvar
+
diff --git a/lib/ft8var/packjt77sdvar.f90 b/lib/ft8var/packjt77sdvar.f90 new file mode 100755 index 00000000..a55a7015 --- /dev/null +++ b/lib/ft8var/packjt77sdvar.f90 @@ -0,0 +1,558 @@ +
+module packjt77sdvar
+
+! These variables are accessible from outside via "use packjt77sdvar":
+! integer n28a,n28b
+
+ contains
+
+subroutine pack77sdvar(msg0,i3,n3,c77)
+
+ use packjt
+ character*37 msg,msg0
+ character*13 w(19)
+ character*77 c77
+ integer nw(19)
+
+ msg=msg0
+
+! Convert msg to upper case; collapse multiple blanks; parse into words.
+ call split77var(msg,nwords,nw,w)
+ i3=-1
+ n3=-1
+ if(msg(1:3).eq.'CQ ' .or. msg(1:3).eq.'DE ' .or. msg(1:4).eq.'QRZ ') go to 100
+
+! Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P"
+100 call pack77_1var(nwords,w,i3,n3,c77)
+ if(i3.ge.0) go to 900
+
+! It defaults to free text
+ i3=0
+ n3=0
+ msg(14:)=' '
+ call packtext77var(msg(1:13),c77(1:71))
+ write(c77(72:77),'(2b3.3)') n3,i3
+
+900 return
+end subroutine pack77sdvar
+
+subroutine unpack77sdvar(c77,msg,unpk77_success)
+
+ parameter (MAXGRID4=32400)
+ integer*8 n58
+ character*77 c77*77,msg*37,c*38,call_1*13,call_2*13,c11*11,grid4*4,crpt*3
+ logical unpk28_success,unpk77_success
+
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+
+ unpk77_success=.true.
+
+! Check for bad data
+ do i=1,77
+ if(c77(i:i).ne.'0' .and. c77(i:i).ne.'1') then
+ msg='failed unpack'
+ unpk77_success=.false.
+ return
+ endif
+ enddo
+
+ read(c77(72:77),'(2b3)') n3,i3
+ msg=repeat(' ',37)
+ if(i3.eq.0 .and. n3.eq.0) then
+! 0.0 Free text
+ call unpacktext77var(c77(1:71),msg(1:13))
+ msg(14:)=' '
+ msg=adjustl(msg)
+
+ else if(i3.eq.1 .or. i3.eq.2) then
+! Type 1 (standard message) or Type 2 ("/P" form for EU VHF contest)
+ read(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3
+1000 format(2(b28,b1),b1,b15,b3)
+ call unpack28var(n28a,call_1,unpk28_success)
+ if(.not.unpk28_success) unpk77_success=.false.
+ call unpack28var(n28b,call_2,unpk28_success)
+ if(.not.unpk28_success) unpk77_success=.false.
+ if(call_1(1:3).eq.'CQ_') call_1(3:3)=' '
+ if(index(call_1,'<').le.0) then
+ i=index(call_1,' ')
+ if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.1) call_1(i:i+1)='/R'
+ if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.2) call_1(i:i+1)='/P'
+ endif
+ if(index(call_2,'<').le.0) then
+ i=index(call_2,' ')
+ if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.1) call_2(i:i+1)='/R'
+ if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.2) call_2(i:i+1)='/P'
+ endif
+ if(igrid4.le.MAXGRID4) then
+ n=igrid4
+ j1=n/(18*10*10)
+ n=n-j1*18*10*10
+ j2=n/(10*10)
+ n=n-j2*10*10
+ j3=n/10
+ j4=n-j3*10
+ grid4(1:1)=char(j1+ichar('A'))
+ grid4(2:2)=char(j2+ichar('A'))
+ grid4(3:3)=char(j3+ichar('0'))
+ grid4(4:4)=char(j4+ichar('0'))
+ if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//grid4
+ if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//grid4
+ if(msg(1:3).eq.'CQ ' .and. ir.eq.1) unpk77_success=.false.
+ else
+ irpt=igrid4-MAXGRID4
+ if(irpt.eq.1) msg=trim(call_1)//' '//trim(call_2)
+ if(irpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RRR'
+ if(irpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' RR73'
+ if(irpt.eq.4) msg=trim(call_1)//' '//trim(call_2)//' 73'
+ if(irpt.ge.5) then
+ write(crpt,'(i3.2)') irpt-35
+ if(crpt(1:1).eq.' ') crpt(1:1)='+'
+ if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//crpt
+ if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R'//crpt
+ endif
+ if(msg(1:3).eq.'CQ ' .and. irpt.ge.2) unpk77_success=.false.
+ endif
+
+ else if(i3.eq.4) then
+ read(c77,1050) n12,n58,iflip,nrpt,icq
+1050 format(b12,b58,b1,b2,b1)
+ if(icq.eq.1) then
+ do i=11,1,-1
+ j=mod(n58,38)+1
+ c11(i:i)=c(j:j)
+ n58=n58/38
+ enddo
+ call_2=adjustl(c11)//' '
+ msg='CQ '//trim(call_2)
+ if(msg(1:4).eq.'CQ <') unpk77_success=.false.
+ else
+ unpk77_success=.false.
+ endif
+ endif
+
+ return
+end subroutine unpack77sdvar
+
+subroutine pack28var(c13,n28)
+
+! Pack a special token, a 22-bit hash code, or a valid base call into a 28-bit
+! integer.
+
+ parameter (NTOKENS=2063592,MAX22=4194304)
+ logical is_digit,is_letter
+ character*13 c13
+ character*6 callsign
+ character*1 c
+ character*4 c4
+ character*37 a1
+ character*36 a2
+ character*10 a3
+ character*27 a4
+ data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data a3/'0123456789'/
+ data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+
+ is_digit(c)=c.ge.'0' .and. c.le.'9'
+ is_letter(c)=c.ge.'A' .and. c.le.'Z'
+
+ n28=-1
+! Work-around for Swaziland prefix:
+ if(c13(1:4).eq.'3DA0') callsign='3D0'//c13(5:7)
+! Work-around for Guinea prefixes:
+ if(c13(1:2).eq.'3X' .and. c13(3:3).ge.'A' .and. &
+ c13(3:3).le.'Z') callsign='Q'//c13(3:6)
+
+! Check for special tokens first
+ if(c13(1:3).eq.'DE ') then
+ n28=0
+ go to 900
+ endif
+
+ if(c13(1:4).eq.'QRZ ') then
+ n28=1
+ go to 900
+ endif
+
+ if(c13(1:3).eq.'CQ ') then
+ n28=2
+ go to 900
+ endif
+
+ if(c13(1:3).eq.'CQ_') then
+ n=len(trim(c13))
+ if(n.ge.4 .and. n.le.7) then
+ nlet=0
+ nnum=0
+ do i=4,n
+ c=c13(i:i)
+ if(c.ge.'A' .and. c.le.'Z') nlet=nlet+1
+ if(c.ge.'0' .and. c.le.'9') nnum=nnum+1
+ enddo
+ if(nnum.eq.3 .and. nlet.eq.0) then
+ read(c13(4:3+nnum),*) nqsy
+ n28=3+nqsy
+ go to 900
+ endif
+ if(nlet.ge.1 .and. nlet.le.4 .and. nnum.eq.0) then
+ c4=c13(4:n)
+ c4=adjustr(c4)
+ m=0
+ do i=1,4
+ j=0
+ c=c4(i:i)
+ if(c.ge.'A' .and. c.le.'Z') j=ichar(c)-ichar('A')+1
+ m=27*m + j
+ enddo
+ n28=3+1000+m
+ go to 900
+ endif
+ endif
+ endif
+
+! Check for standard callsign
+ iarea=-1
+ n=len(trim(c13))
+ do i=n,2,-1
+ if(is_digit(c13(i:i))) exit
+ enddo
+ iarea=i !Call-area digit
+ npdig=0 !Digits before call area
+ nplet=0 !Letters before call area
+ do i=1,iarea-1
+ if(is_digit(c13(i:i))) npdig=npdig+1
+ if(is_letter(c13(i:i))) nplet=nplet+1
+ enddo
+ nslet=0
+ do i=iarea+1,n
+ if(is_letter(c13(i:i))) nslet=nslet+1
+ enddo
+
+ n=len(trim(c13))
+! This is a standard callsign
+ if(iarea.eq.2) callsign=' '//c13(1:5)
+ if(iarea.eq.3) callsign=c13(1:6)
+ i1=index(a1,callsign(1:1))-1
+ i2=index(a2,callsign(2:2))-1
+ i3=index(a3,callsign(3:3))-1
+ i4=index(a4,callsign(4:4))-1
+ i5=index(a4,callsign(5:5))-1
+ i6=index(a4,callsign(6:6))-1
+ n28=36*10*27*27*27*i1 + 10*27*27*27*i2 + 27*27*27*i3 + 27*27*i4 + &
+ 27*i5 + i6
+ n28=n28 + NTOKENS + MAX22
+
+900 n28=iand(n28,ishft(1,28)-1)
+ return
+end subroutine pack28var
+
+
+subroutine unpack28var(n28_0,c13,success)
+
+ parameter (NTOKENS=2063592,MAX22=4194304)
+ logical success
+ 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'/
+
+ success=.true.
+ 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
+
+! 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 i0=index(c13,' ')
+ if(i0.ne.0 .and. i0.lt.len(trim(c13))) then
+ c13='QU1RK'
+ success=.false.
+ endif
+ return
+end subroutine unpack28var
+
+subroutine split77var(msg,nwords,nw,w)
+
+! Convert msg to upper case; collapse multiple blanks; parse into words.
+
+ character*37 msg
+ character*13 w(19)
+ character*1 c,c0
+ character*6 bcall_1
+ logical ok1
+ integer nw(19)
+
+ iz=len(trim(msg))
+ j=0
+ k=0
+ n=0
+ c0=' '
+ w=' '
+ do i=1,iz
+ if(ichar(msg(i:i)).eq.0) msg(i:i)=' '
+ c=msg(i:i) !Single character
+ if(c.eq.' ' .and. c0.eq.' ') cycle !Skip leading/repeated blanks
+ if(c.ne.' ' .and. c0.eq.' ') then
+ k=k+1 !New word
+ n=0
+ endif
+ j=j+1 !Index in msg
+ n=n+1 !Index in word
+ if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case
+ msg(j:j)=c
+ if(n.le.13) w(k)(n:n)=c !Copy character c into word
+ c0=c
+ enddo
+ iz=j !Message length
+ nwords=k !Number of words in msg
+ if(nwords.le.0) go to 900
+ nw(k)=len(trim(w(k)))
+ msg(iz+1:)=' '
+ if(nwords.lt.3) go to 900
+ call chkcall(w(3),bcall_1,ok1)
+ if(ok1 .and. w(1)(1:3).eq.'CQ ') then
+ w(1)='CQ_'//w(2)(1:10) !Make "CQ " into "CQ_"
+ w(2:12)=w(3:13) !Move all remeining words down by one
+ nwords=nwords-1
+ endif
+
+900 return
+end subroutine split77var
+
+subroutine pack77_1var(nwords,w,i3,n3,c77)
+! Check Type 1 (Standard 77-bit message) and Type 2 (ditto, with a "/P" call)
+
+ parameter (MAXGRID4=32400)
+ character*13 w(19),c13
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ character*4 grid4
+ character c1*1,c2*2
+ logical is_grid4
+ logical ok1,ok2
+ is_grid4(grid4)=len(trim(grid4)).eq.4 .and. &
+ grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. &
+ grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. &
+ grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. &
+ grid4(4:4).ge.'0' .and. grid4(4:4).le.'9'
+
+ if(nwords.lt.2 .or. nwords.gt.4) return
+ call chkcall(w(1),bcall_1,ok1)
+ call chkcall(w(2),bcall_2,ok2)
+ if(w(1)(1:3).eq.'DE ' .or. w(1)(1:3).eq.'CQ_' .or. w(1)(1:3).eq.'CQ ' .or. &
+ w(1)(1:4).eq.'QRZ ') ok1=.true.
+ if(w(1)(1:1).eq.'<' .and. index(w(1),'>').ge.5) ok1=.true.
+ if(w(2)(1:1).eq.'<' .and. index(w(2),'>').ge.5) ok2=.true.
+ if(.not.ok1 .or. .not.ok2) return
+ if(w(1)(1:1).eq.'<' .and. index(w(2),'/').gt.0) return
+ if(w(2)(1:1).eq.'<' .and. index(w(1),'/').gt.0) return
+ if(nwords.eq.2 .and. (.not.ok2 .or. index(w(2),'/').ge.2)) return
+ if(nwords.eq.2) go to 10
+
+ c1=w(nwords)(1:1)
+ c2=w(nwords)(1:2)
+ if(.not.is_grid4(w(nwords)(1:4)) .and. c1.ne.'+' .and. c1.ne.'-' &
+ .and. c2.ne.'R+' .and. c2.ne.'R-' .and. trim(w(nwords)).ne.'RRR' .and. &
+ trim(w(nwords)).ne.'RR73' .and. trim(w(nwords)).ne.'73') return
+ if(c1.eq.'+' .or. c1.eq.'-') then
+ ir=0
+ read(w(nwords),*,err=900) irpt
+ irpt=irpt+35
+ else if(c2.eq.'R+' .or. c2.eq.'R-') then
+ ir=1
+ read(w(nwords)(2:),*) irpt
+ irpt=irpt+35
+ else if(trim(w(nwords)).eq.'RRR') then
+ ir=0
+ irpt=2
+ else if(trim(w(nwords)).eq.'RR73') then
+ ir=0
+ irpt=3
+ else if(trim(w(nwords)).eq.'73') then
+ ir=0
+ irpt=4
+ endif
+
+! 1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg
+! 2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest
+
+10 i1psuffix=index(w(1)//' ' ,'/P ')
+ i2psuffix=index(w(2)//' ','/P ')
+ if(nwords.eq.2 .or. nwords.eq.3 .or. (nwords.eq.4 .and. &
+ w(3)(1:2).eq.'R ')) then
+ n3=0
+ i3=1 !Type 1: Standard message, possibly with "/R"
+ if (i1psuffix.ge.4.or.i2psuffix.ge.4) i3=2 !Type 2, with "/P"
+ endif
+ c13=bcall_1
+ if(c13(1:3).eq.'CQ_' .or. w(1)(1:1).eq.'<') c13=w(1)
+ call pack28var(c13,n28a)
+ c13=bcall_2
+ if(w(2)(1:1).eq.'<') c13=w(2)
+ call pack28var(c13,n28b)
+ ipa=0
+ ipb=0
+ if(i1psuffix.ge.4.or.index(w(1)//' ','/R ').ge.4) ipa=1
+ if(i2psuffix.ge.4.or.index(w(2)//' ','/R ').ge.4) ipb=1
+
+ grid4=w(nwords)(1:4)
+ if(is_grid4(grid4)) then
+ ir=0
+ if(w(3).eq.'R ') ir=1
+ j1=(ichar(grid4(1:1))-ichar('A'))*18*10*10
+ j2=(ichar(grid4(2:2))-ichar('A'))*10*10
+ j3=(ichar(grid4(3:3))-ichar('0'))*10
+ j4=(ichar(grid4(4:4))-ichar('0'))
+ igrid4=j1+j2+j3+j4
+ else
+ igrid4=MAXGRID4 + irpt
+ endif
+ if(nwords.eq.2) then
+ ir=0
+ irpt=1
+ igrid4=MAXGRID4+irpt
+ endif
+ write(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3
+1000 format(2(b28.28,b1),b1,b15.15,b3.3)
+ return
+
+900 return
+end subroutine pack77_1var
+
+subroutine packtext77var(c13,c71)
+
+ character*13 c13,w
+ character*71 c71
+ character*42 c
+ character*1 qa(10),qb(10)
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/
+
+ call mp_short_init
+ qa=char(0)
+ w=adjustr(c13)
+ do i=1,13
+ j=index(c,w(i:i))-1
+ if(j.lt.0) j=0
+ call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9)
+ call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j
+ enddo
+
+ write(c71,1010) qa(2:10)
+1010 format(b7.7,8b8.8)
+
+ return
+end subroutine packtext77var
+
+subroutine unpacktext77var(c71,c13)
+
+ integer*1 ia(10)
+ character*1 qa(10),qb(10)
+ character*13 c13
+ character*71 c71
+ character*42 c
+ equivalence (qa,ia),(qb,ib)
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/
+
+ qa(1)=char(0)
+ read(c71,1010) qa(2:10)
+1010 format(b7.7,8b8.8)
+
+ do i=13,1,-1
+ call mp_short_div(qb,qa(2:10),9,42,ir)
+ c13(i:i)=c(ir+1:ir+1)
+ qa(2:10)=qb(1:9)
+ enddo
+
+ return
+end subroutine unpacktext77var
+
+subroutine mp_short_opsvar(w,u)
+ character*1 w(*),u(*)
+ integer i,ireg,j,n,ir,iv,ii1,ii2
+ character*1 creg(4)
+ save ii1,ii2
+ equivalence (ireg,creg)
+
+ entry mp_short_init
+ ireg=256*ichar('2')+ichar('1')
+ do j=1,4
+ if (creg(j).eq.'1') ii1=j
+ if (creg(j).eq.'2') ii2=j
+ enddo
+ return
+
+ entry mp_short_add(w,u,n,iv)
+ ireg=256*iv
+ do j=n,1,-1
+ ireg=ichar(u(j))+ichar(creg(ii2))
+ w(j+1)=creg(ii1)
+ enddo
+ w(1)=creg(ii2)
+ return
+
+ entry mp_short_mult(w,u,n,iv)
+ ireg=0
+ do j=n,1,-1
+ ireg=ichar(u(j))*iv+ichar(creg(ii2))
+ w(j+1)=creg(ii1)
+ enddo
+ w(1)=creg(ii2)
+ return
+
+ entry mp_short_div(w,u,n,iv,ir)
+ ir=0
+ do j=1,n
+ i=256*ir+ichar(u(j))
+ w(j)=char(i/iv)
+ ir=mod(i,iv)
+ enddo
+ return
+
+ return
+end subroutine mp_short_opsvar
+
+end module packjt77sdvar
diff --git a/lib/ft8var/packjt77var.f90 b/lib/ft8var/packjt77var.f90 new file mode 100755 index 00000000..46d1e760 --- /dev/null +++ b/lib/ft8var/packjt77var.f90 @@ -0,0 +1,1805 @@ +module packjt77var
+
+! use packjt77, only : hash10,hash12,hash22
+
+! These variables are accessible from outside via "use packjt77var":
+ parameter (MAXHASH=1000,MAXTXHASH=5,MAXRECENT=10)
+ character (len=13), dimension(0:1023) :: calls10=''
+ character (len=13), dimension(0:4095) :: calls12=''
+ character (len=13), dimension(1:MAXHASH) :: calls22=''
+ character (len=13), dimension(0:1023) :: txcalls10=''
+ character (len=13), dimension(0:4095) :: txcalls12=''
+ character (len=13), dimension(1:MAXTXHASH) :: txcalls22=''
+ character (len=13), dimension(1:MAXRECENT) :: recent_calls=''
+ character (len=13), dimension(1:840) :: last_calls=''
+ character (len=13) :: mycall13=''
+ character (len=13) :: dxcall13=''
+ character (len=13) :: mycall13_0=''
+ character (len=13) :: dxcall13_0=''
+ integer hashmy10,hashmy12,hashmy22,hashdx10
+ logical :: dxcall13_set=.false.
+ logical :: mycall13_set=.false.
+
+ integer, dimension(1:MAXHASH) :: ihash22=-1
+ integer, dimension(1:5) :: itxhash22=-1
+ integer, dimension(1:24) :: nlast_calls=0
+ integer, dimension(1:25) :: nthrindex=(/0,200,300,370,420,460,500,530,560,590,610,630,650,670,690,710, &
+ 730,750,770,790,800,810,820,830,840/)
+ integer :: nzhash=0
+ integer :: nztxhash=0
+ integer n28a,n28b
+!$omp threadprivate(recent_calls,n28a,n28b)
+ logical(1) lcommonft8b
+
+ contains
+
+subroutine hash10var(n10,c13,nthr)
+
+ character*13 c13
+ integer, intent(in) :: nthr
+
+ c13='<...>'
+ if(n10.lt.0 .or. n10.gt.1023) return
+ if(nthr.gt.25) then ! TX message
+ if(len(trim(txcalls10(n10))).gt.0) then
+ c13=txcalls10(n10)
+ c13='<'//trim(c13)//'>'
+ endif
+ else
+ if(len(trim(calls10(n10))).gt.0) then
+ c13=calls10(n10)
+ c13='<'//trim(c13)//'>'
+ endif
+ endif
+ return
+
+end subroutine hash10var
+
+subroutine hash12var(n12,c13,nthr)
+
+ character*13 c13
+ integer, intent(in) :: nthr
+
+ c13='<...>'
+ if(n12.lt.0 .or. n12.gt.4095) return
+ if(nthr.gt.25) then ! TX message
+ if(len(trim(txcalls12(n12))).gt.0) then
+ c13=txcalls12(n12)
+ c13='<'//trim(c13)//'>'
+ endif
+ else
+ if(len(trim(calls12(n12))).gt.0) then
+ c13=calls12(n12)
+ c13='<'//trim(c13)//'>'
+ endif
+ endif
+
+ return
+
+end subroutine hash12var
+
+
+subroutine hash22var(n22,c13,nthr)
+
+ character*13 c13
+ integer, intent(in) :: nthr
+
+ c13='<...>'
+ if(nthr.gt.25) then ! TX message
+ do i=1,nztxhash
+ if(itxhash22(i).eq.n22) then
+ c13=txcalls22(i)
+ c13='<'//trim(c13)//'>'
+ go to 900
+ endif
+ enddo
+ else
+ do i=1,nzhash
+ if(ihash22(i).eq.n22) then
+ c13=calls22(i)
+ c13='<'//trim(c13)//'>'
+ go to 900
+ endif
+ enddo
+ endif
+
+900 return
+end subroutine hash22var
+
+
+integer function ihashcall(c0,m)
+
+ integer*8 n8
+ character*13 c0
+ character*38 c
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+
+ n8=0
+ do i=1,11
+ j=index(c,c0(i:i)) - 1
+ n8=38*n8 + j
+ enddo
+ ihashcall=ishft(47055833459_8*n8,m-64)
+
+ return
+end function ihashcall
+
+subroutine save_hash_mycallvar(c13,n10,n12,n22)
+
+ character*13 c13,cw
+
+ cw=c13
+ if(cw(1:1).eq.' ' .or. cw(1:5).eq.'<...>') return
+ if(cw(1:1).eq.'<') cw=cw(2:)
+ i=index(cw,'>')
+ if(i.gt.0) cw(i:)=' '
+ if(len(trim(cw)) .lt. 3) return
+
+ n12=ihashcall(cw,12)
+ if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) calls12(n12)=cw
+
+ n10=ihashcall(cw,10)
+ if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) calls10(n10)=cw
+
+ n22=ihashcall(cw,22)
+ if(any(ihash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one
+ where(ihash22.eq.n22) calls22=cw
+ go to 1900
+ endif
+
+! New entry: move table down, making room for new one at the top
+ ihash22(nzhash:2:-1)=ihash22(nzhash-1:1:-1)
+
+! Add the new entry
+ calls22(nzhash:2:-1)=calls22(nzhash-1:1:-1)
+ ihash22(1)=n22
+ calls22(1)=cw
+ if(nzhash.lt.MAXHASH) nzhash=nzhash+1
+
+1900 continue
+
+ return
+end subroutine save_hash_mycallvar
+
+subroutine save_hash_txcallvar(c13,n10,n12,n22,lhashit)
+
+ character*13 c13,cw
+ logical, intent(in) :: lhashit
+
+ cw=c13
+ if(cw(1:1).eq.' ' .or. cw(1:5).eq.'<...>') return
+ if(cw(1:1).eq.'<') cw=cw(2:)
+ i=index(cw,'>')
+ if(i.gt.0) cw(i:)=' '
+
+ if(len(trim(cw)) .lt. 3) return
+
+ n12=ihashcall(cw,12)
+
+ if(lhashit) then
+ if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) txcalls12(n12)=cw
+
+ n10=ihashcall(cw,10)
+ if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) txcalls10(n10)=cw
+
+ n22=ihashcall(cw,22)
+ if(any(itxhash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one
+ where(itxhash22.eq.n22) txcalls22=cw
+ go to 1900
+ endif
+
+! New entry: move table down, making room for new one at the top
+ itxhash22(nztxhash:2:-1)=itxhash22(nztxhash-1:1:-1)
+
+! Add the new entry
+ txcalls22(nztxhash:2:-1)=txcalls22(nztxhash-1:1:-1)
+ itxhash22(1)=n22
+ txcalls22(1)=cw
+ if(nztxhash.lt.MAXTXHASH) nztxhash=nztxhash+1
+
+1900 continue
+ endif
+
+ return
+end subroutine save_hash_txcallvar
+
+subroutine save_hash_callvar(c13,nthr)
+
+ character*13 c13,cw
+ integer, intent(in) :: nthr
+
+ if(nthr.gt.24) return
+ cw=c13
+ if(cw(1:1).eq.' ' .or. cw(1:5).eq.'<...>') return
+ if(cw(1:1).eq.'<') cw=cw(2:)
+ i=index(cw,'>')
+ if(i.gt.0) cw(i:)=' '
+ if(len(trim(cw)) .lt. 3) return
+
+ nposition=nthrindex(nthr)+nlast_calls(nthr)
+ if(nposition.lt.nthrindex(nthr+1)) then
+ nlast_calls(nthr)=nlast_calls(nthr)+1
+ last_calls(nposition+1)=cw
+!print *,nthr,nlast_calls(nthr),nposition+1,last_calls(nposition+1)
+ endif
+
+ return
+end subroutine save_hash_callvar
+
+subroutine pack77var(msg0,i3,n3,c77,ntxhash)
+
+ use packjt
+ character*37 msg,msg0
+ character*18 c18
+ character*13 w(19)
+ character*77 c77
+ integer nw(19)
+ integer ntel(3)
+ integer, intent(in) :: ntxhash
+
+ msg=msg0
+ i3_hint=i3
+ n3_hint=n3
+ i3=-1
+ n3=-1
+ if(i3_hint.eq.0 .and. n3_hint.eq.5) go to 5
+
+! Convert msg to upper case; collapse multiple blanks; parse into words.
+ call split77var(msg,nwords,nw,w)
+ if(msg(1:3).eq.'CQ ' .or. msg(1:3).eq.'DE ' .or. msg(1:4).eq.'QRZ ') go to 100
+
+! Check 0.1 (DXpedition mode)
+ call pack77_01var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0 .or. n3.ge.1) go to 900
+! Check 0.2 (EU VHF contest exchange)
+! call pack77_02(nwords,w,i3,n3,c77)
+! if(i3.ge.0) go to 900
+
+! Check 0.3 and 0.4 (ARRL Field Day exchange)
+ call pack77_03var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0) go to 900
+ if(nwords.ge.2) go to 100
+
+ ! Check 0.5 (telemetry)
+5 i0=index(msg,' ')
+ c18=msg(1:i0-1)
+ c18=adjustr(c18)
+ ntel=-99
+ read(c18,1005,err=6) ntel
+1005 format(3z6)
+ if(ntel(1).ge.2**23) go to 800
+6 if(ntel(1).ge.0 .and. ntel(2).ge.0 .and. ntel(3).ge.0) then
+ i3=0
+ n3=5
+ write(c77,1006) ntel,n3,i3
+1006 format(b23.23,2b24.24,2b3.3)
+ go to 900
+ endif
+
+100 call pack77_06var(nwords,w,i3,n3,c77,i3_hint,n3_hint,ntxhash)
+ if(i3.ge.0) go to 900
+
+! Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P"
+ call pack77_1var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0) go to 900
+
+! Check Type 3 (ARRL RTTY contest exchange)
+ call pack77_3var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0) go to 900
+
+! Check Type 4 (One nonstandard call and one hashed call)
+ call pack77_4var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0) go to 900
+
+! Check Type 5 (EU VHF Contest with 2 hashed calls, report, serial, and grid6)
+ call pack77_5var(nwords,w,i3,n3,c77,ntxhash)
+ if(i3.ge.0) go to 900
+
+! It defaults to free text
+800 i3=0
+ n3=0
+ msg(14:)=' '
+ call packtext77var(msg(1:13),c77(1:71))
+ write(c77(72:77),'(2b3.3)') n3,i3
+
+900 return
+end subroutine pack77var
+
+subroutine unpack77var(c77,nrx,msg,unpk77_success,nthr)
+!
+! nrx=1 when unpacking a received message
+! nrx=0 when unpacking a to-be-transmitted message
+! the value of nrx is used to decide when mycall13 or dxcall13 should
+! be used in place of a callsign from the hashtable
+!
+ parameter (NSEC=86) !Number of ARRL Sections
+ parameter (NUSCAN=171) !Number of States and Provinces
+ parameter (MAXGRID4=32400)
+ integer*8 n58
+ integer ntel(3)
+ character*77 c77
+ character*37 msg
+ character*13 call_1,call_2,call_3,call_1a
+ character*11 c11
+ character*3 crpt,cntx,cpfx
+ character*3 cmult(NUSCAN)
+ character*6 cexch,grid6
+ character*4 grid4,cserial
+ character*3 csec(NSEC)
+ character*38 c
+ character*36 a2
+ logical unpk28_success,unpk77_success,unpkg4_success
+ integer, intent(in) :: nthr
+
+ data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+ data csec/ &
+ "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", &
+ "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", &
+ "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", &
+ "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", &
+ "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", &
+ "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", &
+ "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", &
+ "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", &
+ "WV ","WWA","WY ","DX ","PE ","NB "/
+ data cmult/ &
+ "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", &
+ "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", &
+ "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", &
+ "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", &
+ "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", &
+ "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", &
+ "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", &
+ "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", &
+ "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", &
+ "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", &
+ "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", &
+ "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", &
+ "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", &
+ "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", &
+ "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", &
+ "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", &
+ "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", &
+ "X99"/
+
+ unpk77_success=.true.
+
+! Check for bad data
+ do i=1,77
+ if(c77(i:i).ne.'0' .and. c77(i:i).ne.'1') then
+ msg='failed unpack'
+ unpk77_success=.false.
+ return
+ endif
+ enddo
+
+ read(c77(72:77),'(2b3)') n3,i3
+ msg=repeat(' ',37)
+ if(i3.eq.0 .and. n3.eq.0) then
+! 0.0 Free text
+ call unpacktext77var(c77(1:71),msg(1:13))
+ msg(14:)=' '
+ msg=adjustl(msg)
+ if(msg(1:1).eq.' ') then
+ unpk77_success=.false.
+ return
+ endif
+ else if(i3.eq.0 .and. n3.eq.1) then
+! 0.1 K1ABC RR73; W9XYZ <KH1/KH7Z> -11 28 28 10 5 71 DXpedition Mode
+ read(c77,1010) n28a,n28b,n10,n5
+1010 format(2b28,b10,b5)
+ irpt=2*n5 - 30
+ write(crpt,1012) irpt
+1012 format(i3.2)
+ if(irpt.ge.0) crpt(1:1)='+'
+ call unpack28var(n28a,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false.
+ call unpack28var(n28b,call_2,unpk28_success,nthr)
+ if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false.
+ call hash10var(n10,call_3,nthr)
+! if(call_3.eq.'<...>') then
+! ! print*,'pre std n10 ',n10,' call_3 ',call_3
+! call hash10(n10,call_3)
+! ! print*,'std n10 ',n10,' call_3 ',call_3
+! endif
+
+ if(nrx.eq.1) then
+ if(dxcall13_set .and. len(trim(dxcall13)).ge.3 .and. hashdx10.eq.n10) then; call_3='<'//trim(dxcall13)//'>'
+ elseif(.not.dxcall13_set .and. len(trim(dxcall13)).ge.3 .and. .not.lcommonft8b .and. hashdx10.eq.n10) then
+ call_3='<'//trim(dxcall13_0)//'>'
+ elseif(.not.dxcall13_set .and. len(trim(dxcall13)).ge.3 .and. .not.lcommonft8b .and. hashdx10.ne.n10) then
+ call_3=trim(call_3)
+ elseif(.not.dxcall13_set .and. len(trim(dxcall13)).ge.3 .and. lcommonft8b .and. hashdx10.eq.n10) then
+ call_3='<'//trim(dxcall13_0)//'>'
+ elseif(.not.dxcall13_set .and. len(trim(dxcall13)).ge.3 .and. lcommonft8b .and. hashdx10.ne.n10) then
+ call_3='<...>'
+ endif
+ endif
+ if(nrx.eq.0 .and. mycall13_set .and. n10.eq.hashmy10) call_3='<'//trim(mycall13)//'>'
+ msg=trim(call_1)//' RR73; '//trim(call_2)//' '//trim(call_3)//' '//crpt
+
+ else if(i3.eq.0 .and. n3.eq.2) then
+ unpk77_success=.false.
+
+ else if(i3.eq.0 .and. (n3.eq.3 .or. n3.eq.4)) then
+! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day
+ read(c77,1030) n28a,n28b,ir,intx,nclass,isec
+1030 format(2b28,b1,b4,b3,b7)
+ if(isec.gt.NSEC .or. isec.lt.1) then
+ unpk77_success=.false.
+ isec=1
+ endif
+ call unpack28var(n28a,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false.
+ call unpack28var(n28b,call_2,unpk28_success,nthr)
+ if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false.
+ ntx=intx+1
+ if(n3.eq.4) ntx=ntx+16
+ write(cntx(1:2),1032) ntx
+1032 format(i2)
+ cntx(3:3)=char(ichar('A')+nclass)
+ if(ir.eq.0 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// &
+ cntx//' '//csec(isec)
+ if(ir.eq.1 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// &
+ ' R'//cntx//' '//csec(isec)
+ if(ir.eq.0 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// &
+ ' '//cntx//' '//csec(isec)
+ if(ir.eq.1 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// &
+ ' R '//cntx//' '//csec(isec)
+
+ else if(i3.eq.0 .and. n3.eq.5) then
+! 0.5 0123456789abcdef01 71 71 Telemetry (18 hex)
+ read(c77,1006) ntel
+1006 format(b23,2b24)
+ write(msg,1007) ntel
+1007 format(3z6.6)
+ do i=1,18
+ if(msg(i:i).ne.'0') exit
+ msg(i:i)=' '
+ enddo
+ msg=adjustl(msg)
+
+ else if(i3.eq.0 .and. n3.eq.6) then
+ read(c77(49:50),'(2b1)') j2a,j2b
+ itype=2
+ if(j2b.eq.0 .and. j2a.eq.0) itype=1
+ if(j2b.eq.0 .and. j2a.eq.1) itype=3
+ if(itype.eq.1) then
+! WSPR Type 1
+ read(c77,2010) n28,igrid4,idbm
+2010 format(b28.28,b15.15,b5.5)
+ idbm=nint(idbm*10.0/3.0)
+ call unpack28var(n28,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ call to_grid4var(igrid4,grid4,unpkg4_success)
+ if(.not.unpkg4_success) unpk77_success=.false.
+ write(crpt,'(i3)') idbm
+ msg=trim(call_1)//' '//grid4//' '//trim(adjustl(crpt))
+ if (unpk77_success) call save_hash_callvar(call_1,nthr) !### Is this OK here? ###
+
+ else if(itype.eq.2) then
+! WSPR Type 2
+ read(c77,2020) n28,npfx,idbm
+2020 format(b28.28,b16.16,b5.5)
+ idbm=nint(idbm*10.0/3.0)
+ call unpack28var(n28,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ write(crpt,'(i3)') idbm
+ cpfx=' '
+ if(npfx.lt.nzzz) then
+! Prefix
+ do i=3,1,-1
+ j=mod(npfx,36)+1
+ cpfx(i:i)=a2(j:j)
+ npfx=npfx/36
+ if(npfx.eq.0) exit
+ enddo
+ msg=trim(adjustl(cpfx))//'/'//trim(call_1)//' '//trim(adjustl(crpt))
+ call_1a=trim(adjustl(cpfx))//'/'//trim(call_1)
+ call save_hash_callvar(call_1a,nthr) !### Is this OK here? ###
+ else
+! Suffix
+ npfx=npfx-nzzz
+ if(npfx.le.35) then
+ cpfx(1:1)=a2(npfx+1:npfx+1)
+ else if(npfx.gt.35 .and. npfx.le.1295) then
+ cpfx(1:1)=a2(npfx/36+1:npfx/36+1)
+ cpfx(2:2)=a2(mod(npfx,36)+1:mod(npfx,36)+1)
+ else if(npfx.gt.1295 .and. npfx.le.12959) then
+ cpfx(1:1)=a2(npfx/360+1:npfx/360+1)
+ cpfx(2:2)=a2(mod(npfx/10,36)+1:mod(npfx/10,36)+1)
+ cpfx(3:3)=a2(mod(npfx,10)+1:mod(npfx,10)+1)
+ else
+ unpk77_success=.false.
+ return
+ endif
+ msg=trim(call_1)//'/'//trim(adjustl(cpfx))//' '//trim(adjustl(crpt))
+ call_1a=trim(call_1)//'/'//trim(adjustl(cpfx))
+ call save_hash_callvar(call_1a,nthr) !### Is this OK here? ###
+ endif
+
+ else if(itype.eq.3) then
+! WSPR Type 3
+ read(c77,2030) n22,igrid6
+2030 format(b22.22,b25.25)
+ n28=n22+2063592
+ call unpack28var(n28,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ call to_gridvar(igrid6,grid6,unpkg4_success)
+ if(.not.unpkg4_success) unpk77_success=.false.
+ msg=trim(call_1)//' '//grid6
+ endif
+
+ else if(i3.eq.0 .and. n3.gt.6) then
+ unpk77_success=.false.
+
+ else if(i3.eq.1 .or. i3.eq.2) then
+! Type 1 (standard message) or Type 2 ("/P" form for EU VHF contest)
+ read(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3
+1000 format(2(b28,b1),b1,b15,b3)
+ call unpack28var(n28a,call_1,unpk28_success,nthr)
+ if(nrx.eq.1 .and. mycall13_set .and. hashmy22.eq.(n28a-2063592)) then
+ call_1='<'//trim(mycall13)//'>'
+ unpk28_success=.true.
+ endif
+ if(.not.unpk28_success) unpk77_success=.false.
+ call unpack28var(n28b,call_2,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ if(call_1(1:3).eq.'CQ_') call_1(3:3)=' '
+ if(index(call_1,'<').le.0) then
+ i=index(call_1,' ')
+ if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.1) call_1(i:i+1)='/R'
+ if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.2) call_1(i:i+1)='/P'
+ if(i.ge.4) call add_call_to_recent_callsvar(call_1,nthr)
+ endif
+ if(index(call_2,'<').le.0) then
+ i=index(call_2,' ')
+ if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.1) call_2(i:i+1)='/R'
+ if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.2) call_2(i:i+1)='/P'
+ if(i.ge.4) then
+ call add_call_to_recent_callsvar(call_2,nthr)
+! only hash the "from" call
+ call save_hash_callvar(call_2,nthr)
+ endif
+ endif
+ if(igrid4.le.MAXGRID4) then
+ call to_grid4var(igrid4,grid4,unpkg4_success)
+ if(.not.unpkg4_success) unpk77_success=.false.
+ if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//grid4
+ if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//grid4
+ if(msg(1:3).eq.'CQ ' .and. ir.eq.1) unpk77_success=.false.
+!out of current realisation of protocol: GRID is always dropped at WSJT-X/JTDX transmission of the messages below
+! i3 n3
+! 1 0
+!110015 -23 0.5 1450 ~ <...> Y96IHQ/R GL12
+!112215 -23 0.0 1606 ~ <...> 3U1TBM/R CC65
+!000102 -23 0.5 801 ~ <...> NV3QHV/R JF62
+ if(ir.eq.0 .and. call_1(1:1).eq.'<' .and. grid4.ne.'RR73') then ! hash value can also be associated with a valid callsign
+ nlencall2=len_trim(call_2)
+ if(nlencall2.gt.1) then
+ if(call_2(nlencall2-1:nlencall2).eq.'/R') unpk77_success=.false.
+ endif
+ endif
+ else
+ irpt=igrid4-MAXGRID4
+ if(irpt.eq.1) msg=trim(call_1)//' '//trim(call_2)
+ if(irpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RRR'
+ if(irpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' RR73'
+ if(irpt.eq.4) msg=trim(call_1)//' '//trim(call_2)//' 73'
+ if(irpt.ge.5) then
+ isnr=irpt-35
+ if(isnr.gt.50) isnr=isnr-101
+ write(crpt,'(i3.2)') isnr
+ if(crpt(1:1).eq.' ') crpt(1:1)='+'
+ if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//crpt
+ if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R'//crpt
+ endif
+ if(msg(1:3).eq.'CQ ' .and. irpt.ge.2) unpk77_success=.false.
+ endif
+
+ else if(i3.eq.3) then
+! Type 3: ARRL RTTY Contest
+ read(c77,1040) itu,n28a,n28b,ir,irpt,nexch,i3
+1040 format(b1,2b28.28,b1,b3.3,b13.13,b3.3)
+ write(crpt,1042) irpt+2
+1042 format('5',i1,'9')
+ nserial=nexch
+ imult=-1
+ if(nexch.gt.8000) then
+ imult=nexch-8000
+ nserial=-1
+ endif
+ call unpack28var(n28a,call_1,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ call unpack28var(n28b,call_2,unpk28_success,nthr)
+ if(.not.unpk28_success) unpk77_success=.false.
+ imult=0
+ nserial=0
+ if(nexch.gt.8000) imult=nexch-8000
+ if(nexch.lt.8000) nserial=nexch
+
+ if(imult.ge.1 .and.imult.le.NUSCAN) then
+ if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cmult(imult)
+ if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cmult(imult)
+ if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// &
+ ' R '//crpt//' '//cmult(imult)
+ if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' R '//crpt//' '//cmult(imult)
+ else if(nserial.ge.1 .and. nserial.le.7999) then
+ write(cserial,'(i4.4)') nserial
+ if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cserial
+ if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cserial
+ if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// &
+ ' R '//crpt//' '//cserial
+ if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' R '//crpt//' '//cserial
+ endif
+
+ else if(i3.eq.4) then
+! Type 4
+ read(c77,1050) n12,n58,iflip,nrpt,icq
+1050 format(b12,b58,b1,b2,b1)
+ do i=11,1,-1
+ j=mod(n58,38)+1
+ c11(i:i)=c(j:j)
+ n58=n58/38
+ enddo
+ call hash12var(n12,call_3,nthr)
+! if(call_3.eq.'<...>') then
+! ! print*,'pre std n12 1 ',n12,' call_3 ',call_3
+! call hash12(n12,call_3)
+! ! print*,'std n12 1 ',n12,' call_3 ',call_3
+! endif
+ if(iflip.eq.0) then ! 12 bit hash for TO call
+ call_1=call_3
+ call_2=adjustl(c11)//' '
+ call add_call_to_recent_callsvar(call_2,nthr)
+ if(nrx.eq.1 .and. &
+ dxcall13_set .and. mycall13_set .and. &
+ call_2.eq.dxcall13 .and. &
+ n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>'
+ if(nrx.eq.1 .and. &
+ mycall13_set .and. &
+ index(call_1,'<...>').gt.0 .and. &
+ n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>'
+ else ! 12 bit hash for DE call
+ call_1=adjustl(c11)
+ call_2=call_3
+ call add_call_to_recent_callsvar(call_1,nthr)
+ if(nrx.eq.0 .and. &
+ mycall13_set .and. &
+ n12.eq.hashmy12) call_2='<'//trim(mycall13)//'>'
+ endif
+ if(icq.eq.0) then
+ if(nrpt.eq.0) msg=trim(call_1)//' '//trim(call_2)
+ if(nrpt.eq.1) msg=trim(call_1)//' '//trim(call_2)//' RRR'
+ if(nrpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RR73'
+ if(nrpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' 73'
+ else
+ msg='CQ '//trim(call_2)
+ endif
+ if(call_2(1:1).lt.':' .and. call_2(1:1).gt.'/' .and. call_2(2:2).lt.':' .and. call_2(2:2).gt.'/') unpk77_success=.false.
+ if(len_trim(call_2).eq.11) then
+ ispace=index(call_2,' '); if(ispace.gt.0 .and. ispace.lt.12) unpk77_success=.false.
+ islash=index(call_2,'/'); if(islash.eq.1 .or. islash.eq.2 .or. islash.eq.11 .or. (islash.eq.10 .and. &
+ call_2(11:11).gt.'@' .and. call_2(11:11).lt.'[' .and. call_2(11:11).ne.'P')) unpk77_success=.false.
+ if(islash.lt.6 .and. call_2(11:11).lt.':' .and. call_2(11:11).gt.'/') unpk77_success=.false.
+ endif
+ if(msg(1:3).ne.'CQ ') then
+ if(call_1(1:1).lt.':' .and. call_1(1:1).gt.'/' .and. call_1(2:2).lt.':' .and.call_1(2:2).gt.'/') unpk77_success=.false.
+ if(len_trim(call_1).eq.11) then
+ ispace=index(call_1,' '); if(ispace.gt.0 .and. ispace.lt.12) unpk77_success=.false.
+ islash=index(call_1,'/'); if(islash.eq.1 .or. islash.eq.2 .or. islash.eq.11 .or. (islash.eq.10 .and. &
+ call_1(11:11).gt.'@' .and. call_1(11:11).lt.'[' .and. call_1(11:11).ne.'P')) unpk77_success=.false.
+ if(islash.lt.6 .and. call_1(11:11).lt.':' .and. call_1(11:11).gt.'/') unpk77_success=.false.
+ endif
+ endif
+ nmsglen=len_trim(msg)
+! protocol violations, also reported at wrong TX message packing
+! prevent broken message transmission
+ if(unpk77_success .and. nmsglen.gt.0) then
+ indxp=index(msg,'/P ')
+ if((icq.eq.0 .and. nrpt.eq.0 .and. (indxp.lt.1 .or. indxp.gt.7)) .or. icq.eq.1) then
+! -23 -3.3 N0S/W45ETOE <...>
+!071445 -14 0.1 779 ~ <...>
+!071445 -14 0.1 779 ~ W5JZ ! hash was associated
+! CQ <...>
+! with exception to broken by packing message 'JQ1AHT/P <JL1LOF/1> -15' wrongly being transmitted as type 4 message 'JQ1AHT/P <JL1LOF/1>'
+ if(msg(nmsglen:nmsglen).eq.'>') unpk77_success=.false.
+ endif
+ endif
+! <...> /BZZ/0ZZ/C
+! <...> ZZZZ/0Z/Z/
+! <...> OZZZZ/0ZZZ/
+! <...> 0I/IZZZ/O K
+! <...> J/IZZZ/O K
+ if(unpk77_success .and. iflip.eq.0 .and. icq.eq.0 .and. nrpt.eq.0) then
+ nlencall2=len_trim(call_2)
+ if(nlencall2.gt.9) then
+ if(call_2(1:1).eq.'/' .or. call_2(nlencall2:nlencall2).eq.'/') unpk77_success=.false.
+ nindxspace=index(call_2,' ')
+ if(nindxspace.gt.0 .and. nindxspace.lt.nlencall2) unpk77_success=.false.
+ endif
+ endif
+
+ else if(i3.eq.5) then
+
+! Type 5 <PA3XYZ> <G4ABC/P> R 590003 IO91NP h12 h22 r1 s3 S11 g25
+! EU VHF contest
+ read(c77,1060) n12,n22,ir,irpt,iserial,igrid6
+1060 format(b12,b22,b1,b3,b11,b25)
+ if(igrid6.lt.0 .or. igrid6.gt.18662399) then
+ unpk77_success=.false.
+ return
+ endif
+ call hash12var(n12,call_1,nthr)
+! if(call_1.eq.'<...>') then
+! ! print*,'pre std n12 1 ',n12,' call_1 ',call_1
+! call hash12(n12,call_1)
+! ! print*,'std n12 2 ',n12,' call_1 ',call_1
+! endif
+ if(n12.eq.hashmy12) call_1='<'//trim(mycall13)//'>'
+ call hash22var(n22,call_2,nthr)
+! if(call_2.eq.'<...>') then
+! ! print*,'pre std n22 ',n22,' call_2 ',call_2
+! call hash22(n22,call_2)
+! ! print*,'std n22 ',n22,' call_2 ',call_2
+! endif
+ nrs=52+irpt
+ write(cexch,1022) nrs,iserial
+1022 format(i2,i4.4)
+ call to_grid6var(igrid6,grid6,unpk77_success)
+ if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//cexch//' '//grid6
+ if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//cexch//' '//grid6
+
+ else if(i3.ge.6) then ! i3 values 6 and 7 are not yet defined
+ unpk77_success=.false.
+ endif
+ if(msg(1:4).eq.'CQ <') unpk77_success=.false.
+ return
+end subroutine unpack77var
+
+subroutine pack28var(c13,n28,ntxhash)
+
+! Pack a special token, a 22-bit hash code, or a valid base call into a 28-bit
+! integer.
+
+ parameter (NTOKENS=2063592,MAX22=4194304)
+ logical is_digit,is_letter,lhashit
+ character*13 c13
+ character*6 callsign
+ character*1 c
+ character*4 c4
+ character*37 a1
+ character*36 a2
+ character*10 a3
+ character*27 a4
+ integer, intent(in) :: ntxhash
+ data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data a3/'0123456789'/
+ data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+
+ is_digit(c)=c.ge.'0' .and. c.le.'9'
+ is_letter(c)=c.ge.'A' .and. c.le.'Z'
+
+ n28=-1
+! Work-around for Swaziland prefix:
+ if(c13(1:4).eq.'3DA0') callsign='3D0'//c13(5:7)
+! Work-around for Guinea prefixes:
+ if(c13(1:2).eq.'3X' .and. c13(3:3).ge.'A' .and. &
+ c13(3:3).le.'Z') callsign='Q'//c13(3:6)
+
+! Check for special tokens first
+ if(c13(1:3).eq.'DE ') then
+ n28=0
+ go to 900
+ endif
+
+ if(c13(1:4).eq.'QRZ ') then
+ n28=1
+ go to 900
+ endif
+
+ if(c13(1:3).eq.'CQ ') then
+ n28=2
+ go to 900
+ endif
+
+ if(c13(1:3).eq.'CQ_') then
+ n=len(trim(c13))
+ if(n.ge.4 .and. n.le.7) then
+ nlet=0
+ nnum=0
+ do i=4,n
+ c=c13(i:i)
+ if(c.ge.'A' .and. c.le.'Z') nlet=nlet+1
+ if(c.ge.'0' .and. c.le.'9') nnum=nnum+1
+ enddo
+ if(nnum.eq.3 .and. nlet.eq.0) then
+ read(c13(4:3+nnum),*) nqsy
+ n28=3+nqsy
+ go to 900
+ endif
+ if(nlet.ge.1 .and. nlet.le.4 .and. nnum.eq.0) then
+ c4=c13(4:n)
+ c4=adjustr(c4)
+ m=0
+ do i=1,4
+ j=0
+ c=c4(i:i)
+ if(c.ge.'A' .and. c.le.'Z') j=ichar(c)-ichar('A')+1
+ m=27*m + j
+ enddo
+ n28=3+1000+m
+ go to 900
+ endif
+ endif
+ endif
+
+ lhashit=.false.; if(ntxhash.eq.1) lhashit=.true.
+! Check for <...> callsign
+ if(c13(1:1).eq.'<')then
+ call save_hash_txcallvar(c13,n10,n12,n22,lhashit) !Save callsign in hash table
+ i2=index(c13,'>')
+ c13=c13(2:i2-1)
+ n22=ihashcall(c13,22)
+ n28=NTOKENS + n22
+ go to 900
+ endif
+
+! Check for standard callsign
+ iarea=-1
+ n=len(trim(c13))
+ do i=n,2,-1
+ if(is_digit(c13(i:i))) exit
+ enddo
+ iarea=i !Call-area digit
+ npdig=0 !Digits before call area
+ nplet=0 !Letters before call area
+ do i=1,iarea-1
+ if(is_digit(c13(i:i))) npdig=npdig+1
+ if(is_letter(c13(i:i))) nplet=nplet+1
+ enddo
+ nslet=0
+ do i=iarea+1,n
+ if(is_letter(c13(i:i))) nslet=nslet+1
+ enddo
+ if(iarea.lt.2 .or. iarea.gt.3 .or. nplet.eq.0 .or. &
+ npdig.ge.iarea-1 .or. nslet.gt.3) then
+! Treat this as a nonstandard callsign: compute its 22-bit hash
+ call save_hash_txcallvar(c13,n10,n12,n22,lhashit) !Save callsign in hash table
+ n22=ihashcall(c13,22)
+ n28=NTOKENS + n22
+ go to 900
+ endif
+
+ n=len(trim(c13))
+! This is a standard callsign
+ call save_hash_txcallvar(c13,n10,n12,n22,lhashit) !Save callsign in hash table
+ if(iarea.eq.2) callsign=' '//c13(1:5)
+ if(iarea.eq.3) callsign=c13(1:6)
+ i1=index(a1,callsign(1:1))-1
+ i2=index(a2,callsign(2:2))-1
+ i3=index(a3,callsign(3:3))-1
+ i4=index(a4,callsign(4:4))-1
+ i5=index(a4,callsign(5:5))-1
+ i6=index(a4,callsign(6:6))-1
+ n28=36*10*27*27*27*i1 + 10*27*27*27*i2 + 27*27*27*i3 + 27*27*i4 + &
+ 27*i5 + i6
+ n28=n28 + NTOKENS + MAX22
+
+900 n28=iand(n28,ishft(1,28)-1)
+ return
+end subroutine pack28var
+
+
+subroutine unpack28var(n28_0,c13,success,nthr)
+
+ parameter (NTOKENS=2063592,MAX22=4194304)
+ logical success
+ character*13 c13
+ character*37 c1
+ character*36 c2
+ character*10 c3
+ character*27 c4
+ integer, intent(in) :: nthr
+ data c1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data c2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+ data c3/'0123456789'/
+ data c4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
+
+ success=.true.
+ 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 hash22var(n22,c13,nthr) !Retrieve callsign from hash table
+! if(c13.eq.'<...>') then
+! ! print*,'pre std n22 ',n22,' c13 ',c13
+! call hash22(n22,c13)
+! ! print*,'std n22 ',n22,' c13 ',c13
+! 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 i0=index(c13,' ')
+
+ if((i0.ne.0 .and. i0.lt.len(trim(c13))) .or. (c13(1:1).lt.':' .and. c13(1:1).gt.'/' .and. &
+ c13(2:2).lt.':' .and. c13(2:2).gt.'/')) then
+ c13='QU1RK'
+ success=.false.
+ endif
+
+ return
+end subroutine unpack28var
+
+subroutine split77var(msg,nwords,nw,w)
+
+! Convert msg to upper case; collapse multiple blanks; parse into words.
+
+ character*37 msg
+ character*13 w(19)
+ character*1 c,c0
+ character*6 bcall_1
+ logical ok1
+ integer nw(19)
+
+ iz=len(trim(msg))
+ j=0
+ k=0
+ n=0
+ c0=' '
+ w=' '
+ do i=1,iz
+ if(ichar(msg(i:i)).eq.0) msg(i:i)=' '
+ c=msg(i:i) !Single character
+ if(c.eq.' ' .and. c0.eq.' ') cycle !Skip leading/repeated blanks
+ if(c.ne.' ' .and. c0.eq.' ') then
+ k=k+1 !New word
+ n=0
+ endif
+ j=j+1 !Index in msg
+ n=n+1 !Index in word
+ if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case
+ msg(j:j)=c
+ if(n.le.13) w(k)(n:n)=c !Copy character c into word
+ c0=c
+ enddo
+ iz=j !Message length
+ nwords=k !Number of words in msg
+ if(nwords.le.0) go to 900
+ nw(k)=len(trim(w(k)))
+ msg(iz+1:)=' '
+ if(nwords.lt.3) go to 900
+ call chkcall(w(3),bcall_1,ok1)
+ if(ok1 .and. w(1)(1:3).eq.'CQ ') then
+ w(1)='CQ_'//w(2)(1:10) !Make "CQ " into "CQ_"
+ w(2:12)=w(3:13) !Move all remeining words down by one
+ nwords=nwords-1
+ endif
+
+900 return
+end subroutine split77var
+
+
+subroutine pack77_01var(nwords,w,i3,n3,c77,ntxhash)
+
+! Pack a Type 0.1 message: DXpedition mode
+! Example message: "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 28 28 10 5
+
+ character*13 w(19),c13
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ logical ok1,ok2,lhashit
+ integer, intent(in) :: ntxhash
+
+ if(nwords.ne.5) go to 900 !Must have 5 words
+ if(trim(w(2)).ne.'RR73;') go to 900 !2nd word must be "RR73;"
+ if(w(4)(1:1).ne.'<') go to 900 !4th word must have <...>
+ if(index(w(4),'>').lt.1) go to 900
+ n=-99
+ read(w(5),*,err=1) n
+1 if(n.eq.-99) go to 900 !5th word must be a valid report
+ n5=(n+30)/2
+ if(n5.lt.0) n5=0
+ if(n5.gt.31) n5=31
+ call chkcall(w(1),bcall_1,ok1)
+ if(.not.ok1) go to 900 !1st word must be a valid basecall
+ call chkcall(w(3),bcall_2,ok2)
+ if(.not.ok2) go to 900 !3rd word must be a valid basecall
+
+! Type 0.1: K1ABC RR73; W9XYZ <KH1/KH7Z> -11 28 28 10 5 71 DXpedition special msg
+ i3=0
+ n3=1
+ call pack28var(w(1),n28a,ntxhash)
+ call pack28var(w(3),n28b,ntxhash)
+ lhashit=.false.; if(ntxhash.eq.1) lhashit=.true.
+ call save_hash_txcallvar(w(4),n10,n12,n22,lhashit)
+ i2=index(w(4),'>')
+ c13=w(4)(2:i2-1)
+ n10=ihashcall(c13,10)
+ write(c77,1010) n28a,n28b,n10,n5,n3,i3
+1010 format(2b28.28,b10.10,b5.5,2b3.3)
+
+900 return
+end subroutine pack77_01var
+
+subroutine pack77_03var(nwords,w,i3,n3,c77,ntxhash)
+
+! Check 0.3 and 0.4 (ARRL Field Day exchange)
+! Example message: WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71
+
+ parameter (NSEC=86) !Number of ARRL Sections
+ character*13 w(19)
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ character*3 csec(NSEC)
+ logical ok1,ok2
+ integer, intent(in) :: ntxhash
+ data csec/ &
+ "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", &
+ "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", &
+ "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", &
+ "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", &
+ "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", &
+ "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", &
+ "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", &
+ "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", &
+ "WV ","WWA","WY ","DX ","PE ","NB "/
+
+ if(nwords.lt.4 .or. nwords.gt.5) return
+ call chkcall(w(1),bcall_1,ok1)
+ call chkcall(w(2),bcall_2,ok2)
+ if(.not.ok1 .or. .not.ok2) return
+ isec=-1
+ do i=1,NSEC
+ if(csec(i).eq.w(nwords)(1:3)) then
+ isec=i
+ exit
+ endif
+ enddo
+ if(isec.eq.-1) return
+ if(nwords.eq.5 .and. trim(w(3)).ne.'R') return
+
+ ntx=-1
+ j=len(trim(w(nwords-1)))-1
+ read(w(nwords-1)(1:j),*,err=1,end=1) ntx !Number of transmitters
+1 if(ntx.lt.1 .or. ntx.gt.32) return
+ nclass=ichar(w(nwords-1)(j+1:j+1))-ichar('A')
+
+ m=len(trim(w(nwords))) !Length of section abbreviation
+ if(m.lt.2 .or. m.gt.3) return
+
+! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day
+! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day
+
+ i3=0
+ n3=3 !Type 0.3 ARRL Field Day
+ intx=ntx-1
+ if(intx.ge.16) then
+ n3=4 !Type 0.4 ARRL Field Day
+ intx=ntx-17
+ endif
+ call pack28var(w(1),n28a,ntxhash)
+ call pack28var(w(2),n28b,ntxhash)
+ ir=0
+ if(w(3)(1:2).eq.'R ') ir=1
+ write(c77,1010) n28a,n28b,ir,intx,nclass,isec,n3,i3
+1010 format(2b28.28,b1,b4.4,b3.3,b7.7,2b3.3)
+
+ return
+end subroutine pack77_03var
+
+subroutine pack77_06var(nwords,w,i3,n3,c77,i3_hint,n3_hint,ntxhash)
+
+ character*13 w(19)
+ character*77 c77
+ character*6 bcall,grid6
+ character*4 grid4
+ character*1 c
+ character*36 a2
+ integer, intent(in) :: ntxhash
+ data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/
+
+ logical is_grid4,is_grid6,is_digit,ok
+ is_grid4(grid4)=len(trim(grid4)).eq.4 .and. &
+ grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. &
+ grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. &
+ grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. &
+ grid4(4:4).ge.'0' .and. grid4(4:4).le.'9'
+
+ is_grid6(grid6)=(len(trim(grid6)).eq.6.or.len(trim(grid6)).eq.4).and. &
+ grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. &
+ grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. &
+ grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. &
+ grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. &
+ (len(trim(grid6)).eq.4.or. &
+ (grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. &
+ grid6(6:6).ge.'A' .and. grid6(6:6).le.'X'))
+
+ is_digit(c)=c.ge.'0' .and. c.le.'9'
+
+ m1=len(trim(w(1)))
+ m2=len(trim(w(2)))
+ m3=len(trim(w(3)))
+ if(nwords.eq.3 .and. m1.ge.3 .and. m1.le.6 .and. m2.eq.4 .and. m3.le.2) then
+! WSPR Type 1
+ if(.not.is_grid4(w(2)(1:4))) go to 900
+ if(.not.is_digit(w(3)(1:1))) go to 900
+ if(m3.eq.2) then
+ if(.not.is_digit(w(3)(2:2))) go to 900
+ endif
+ i3=0
+ n3=6
+ call pack28var(w(1),n28,ntxhash)
+ grid4=w(2)(1:4)
+ k1=(ichar(grid4(1:1))-ichar('A'))*18*10*10
+ k2=(ichar(grid4(2:2))-ichar('A'))*10*10
+ k3=(ichar(grid4(3:3))-ichar('0'))*10
+ k4=(ichar(grid4(4:4))-ichar('0'))
+ igrid4=k1+k2+k3+k4
+ read(w(3),*) idbm
+ if(idbm.lt.0) idbm=0
+ if(idbm.gt.60) idbm=60
+ idbm=nint(0.3*idbm)
+ write(c77,1010) n28,igrid4,idbm,0,0,0,n3,i3
+1010 format(b28.28,b15.15,b5.5,2i1,b21.21,2b3.3)
+ go to 900
+ endif
+ if(nwords.eq.2 .and. m1.ge.5 .and. m1.le.10 .and. m2.le.2) then
+! WSPR Type 2
+ i1=index(w(1),'/')
+ if(i1.lt.2 .or. i1.eq.m1) go to 900
+ if(.not.is_digit(w(2)(1:1))) go to 900
+ if(i1.eq.(m1-3) .and. .not.is_digit(w(1)(m1:m1))) go to 900
+ if(m2.eq.2) then
+ if(.not.is_digit(w(2)(2:2))) go to 900
+ endif
+ call chkcall(w(1),bcall,ok)
+ if(.not.ok) go to 900
+ if(i1.le.4) then
+! We have a prefix
+ npfx=index(a2,w(1)(1:1))-1
+ if(i1.ge.3) npfx=36*npfx + index(a2,w(1)(2:2))-1
+ if(i1.eq.4) npfx=36*npfx + index(a2,w(1)(3:3))-1
+ else
+! We have a suffix
+ if((m1-i1).eq.1) npfx=index(a2,w(1)(i1+1:i1+1))-1
+ if((m1-i1).eq.2) npfx=36*(index(a2,w(1)(i1+1:i1+1))-1) + &
+ index(a2,w(1)(i1+2:i1+2))-1
+ if((m1-i1).eq.3) then
+! Third character of a suffix must be a digit
+ if(.not.is_digit(w(1)(i1+3:i1+3))) go to 900
+ npfx=36*10*(index(a2,w(1)(i1+1:i1+1))-1) + &
+ 10*(index(a2,w(1)(i1+2:i1+2))-1) + index(a2,w(1)(i1+3:i1+3))-1
+ endif
+ npfx=npfx + nzzz
+ endif
+ i3=0
+ n3=6
+ call pack28var(bcall//' ',n28,ntxhash)
+ read(w(2),*) idbm
+ if(idbm.lt.0) idbm=0
+ if(idbm.gt.60) idbm=60
+ idbm=nint(0.3*idbm)
+ write(c77,1020) n28,npfx,idbm,1,0,n3,i3
+1020 format(b28.28,b16.16,b5.5,i1,b21.21,2b3.3)
+ go to 900
+ endif
+
+ if(i3_hint.eq.0.and.n3_hint.eq.6.and.nwords.eq.2 .and. m1.ge.5 &
+ .and. m1.le.12 .and. m2.le.6) then
+! WSPR Type 3
+
+ !n3_hint=6 and i3_hint=0 is a hint that the caller wanted a
+ !50-bit encoding rather than the possible alternative n3=4 77-bit
+ !encoding
+ if(index(w(1),'<').lt.1 .or. index(w(1),'>').lt.1) go to 900
+ grid6=w(2)(1:6)
+ if(.not.is_grid6(grid6)) go to 900
+ i3=0
+ n3=6
+ call pack28var(w(1),n28,ntxhash)
+ n22=n28-2063592
+ k1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*25*25
+ k2=(ichar(grid6(2:2))-ichar('A'))*10*10*25*25
+ k3=(ichar(grid6(3:3))-ichar('0'))*10*25*25
+ k4=(ichar(grid6(4:4))-ichar('0'))*25*25
+ if (grid6(5:6).eq.' ') then
+ igrid6=k1+k2+k3+k4+24*25+24
+ else
+ k5=(ichar(grid6(5:5))-ichar('A'))*25
+ k6=(ichar(grid6(6:6))-ichar('A'))
+ igrid6=k1+k2+k3+k4+k5+k6
+ endif
+ write(c77,1030) n22,igrid6,2,0,n3,i3
+1030 format(b22.22,b25.25,b3.3,b21.21,2b3.3)
+ endif
+
+900 return
+end subroutine pack77_06var
+
+subroutine pack77_1var(nwords,w,i3,n3,c77,ntxhash)
+
+! Check Type 1 (Standard 77-bit message) and Type 2 (ditto, with a "/P" call)
+! Example message: WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74
+
+ parameter (MAXGRID4=32400)
+ character*13 w(19),c13
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ character*4 grid4
+ character c1*1,c2*2
+ logical is_grid4
+ logical ok1,ok2
+ integer, intent(in) :: ntxhash
+ is_grid4(grid4)=len(trim(grid4)).eq.4 .and. &
+ grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. &
+ grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. &
+ grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. &
+ grid4(4:4).ge.'0' .and. grid4(4:4).le.'9'
+
+ if(nwords.lt.2 .or. nwords.gt.4) return
+ call chkcall(w(1),bcall_1,ok1)
+ call chkcall(w(2),bcall_2,ok2)
+ if(w(1)(1:3).eq.'DE ' .or. w(1)(1:3).eq.'CQ_' .or. w(1)(1:3).eq.'CQ ' .or. &
+ w(1)(1:4).eq.'QRZ ') ok1=.true.
+ if(w(1)(1:1).eq.'<' .and. index(w(1),'>').ge.5) ok1=.true.
+ if(w(2)(1:1).eq.'<' .and. index(w(2),'>').ge.5) ok2=.true.
+ if(.not.ok1 .or. .not.ok2) return
+ if(w(1)(1:1).eq.'<' .and. index(w(2),'/').gt.0) return
+ if(w(2)(1:1).eq.'<' .and. index(w(1),'/').gt.0) return
+ if(nwords.eq.2 .and. (.not.ok2 .or. index(w(2),'/').ge.2)) return
+ if(nwords.eq.2) go to 10
+
+ c1=w(nwords)(1:1)
+ c2=w(nwords)(1:2)
+ if(.not.is_grid4(w(nwords)(1:4)) .and. c1.ne.'+' .and. c1.ne.'-' &
+ .and. c2.ne.'R+' .and. c2.ne.'R-' .and. trim(w(nwords)).ne.'RRR' .and. &
+ trim(w(nwords)).ne.'RR73' .and. trim(w(nwords)).ne.'73') return
+ if(c1.eq.'+' .or. c1.eq.'-') then
+ ir=0
+ read(w(nwords),*,err=900) irpt
+ if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101
+ irpt=irpt+35
+ else if(c2.eq.'R+' .or. c2.eq.'R-') then
+ ir=1
+ read(w(nwords)(2:),*,err=900) irpt
+ if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101
+ irpt=irpt+35
+ else if(trim(w(nwords)).eq.'RRR') then
+ ir=0
+ irpt=2
+ else if(trim(w(nwords)).eq.'RR73') then
+ ir=0
+ irpt=3
+ else if(trim(w(nwords)).eq.'73') then
+ ir=0
+ irpt=4
+ endif
+
+! 1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg
+! 2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest
+
+10 i1psuffix=index(w(1)//' ' ,'/P ')
+ i2psuffix=index(w(2)//' ','/P ')
+ if(nwords.eq.2 .or. nwords.eq.3 .or. (nwords.eq.4 .and. &
+ w(3)(1:2).eq.'R ')) then
+ n3=0
+ i3=1 !Type 1: Standard message, possibly with "/R"
+ if (i1psuffix.ge.4.or.i2psuffix.ge.4) i3=2 !Type 2, with "/P"
+ endif
+ c13=bcall_1
+ if(c13(1:3).eq.'CQ_' .or. w(1)(1:1).eq.'<') c13=w(1)
+ call pack28var(c13,n28a,ntxhash)
+ c13=bcall_2
+ if(w(2)(1:1).eq.'<') c13=w(2)
+ call pack28var(c13,n28b,ntxhash)
+ ipa=0
+ ipb=0
+ if(i1psuffix.ge.4.or.index(w(1)//' ','/R ').ge.4) ipa=1
+ if(i2psuffix.ge.4.or.index(w(2)//' ','/R ').ge.4) ipb=1
+
+ grid4=w(nwords)(1:4)
+ if(is_grid4(grid4)) then
+ ir=0
+ if(w(3).eq.'R ') ir=1
+ j1=(ichar(grid4(1:1))-ichar('A'))*18*10*10
+ j2=(ichar(grid4(2:2))-ichar('A'))*10*10
+ j3=(ichar(grid4(3:3))-ichar('0'))*10
+ j4=(ichar(grid4(4:4))-ichar('0'))
+ igrid4=j1+j2+j3+j4
+ else
+ igrid4=MAXGRID4 + irpt
+ endif
+ if(nwords.eq.2) then
+ ir=0
+ irpt=1
+ igrid4=MAXGRID4+irpt
+ endif
+ write(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3
+1000 format(2(b28.28,b1),b1,b15.15,b3.3)
+ return
+
+900 return
+end subroutine pack77_1var
+
+
+subroutine pack77_3var(nwords,w,i3,n3,c77,ntxhash)
+! Check Type 3 (ARRL RTTY contest exchange)
+!ARRL RTTY - US/Can: rpt state/prov R 579 MA
+! - DX: rpt serial R 559 0013
+! Example message: TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74
+
+ parameter (NUSCAN=171) !Number of US states and Canadian provinces/territories
+ character*13 w(19)
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ character*3 cmult(NUSCAN),mult
+ character crpt*3
+ integer, intent(in) :: ntxhash
+ logical ok1,ok2
+ data cmult/ &
+ "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", &
+ "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", &
+ "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", &
+ "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", &
+ "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", &
+ "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", &
+ "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", &
+ "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", &
+ "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", &
+ "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", &
+ "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", &
+ "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", &
+ "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", &
+ "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", &
+ "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", &
+ "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", &
+ "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", &
+ "X99"/
+
+ if(w(1)(1:1).eq.'<' .and. w(2)(1:1).eq.'<') go to 900
+ 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: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
+ endif
+1 mult=' '
+ imult=-1
+ do i=1,NUSCAN
+ if(cmult(i).eq.w(nwords)) then
+ imult=i
+ mult=cmult(i)
+ exit
+ endif
+ enddo
+ nexch=0
+ if(nserial.gt.0) nexch=nserial
+ if(imult.gt.0) nexch=8000+imult
+ if(mult.ne.' ' .or. nserial.gt.0) then
+ i3=3
+ n3=0
+ itu=0
+ if(trim(w(1)).eq.'TU;') itu=1
+ call pack28var(w(1+itu),n28a,ntxhash)
+ call pack28var(w(2+itu),n28b,ntxhash)
+ ir=0
+ if(w(3+itu)(1:2).eq.'R ') ir=1
+ read(w(3+itu+ir),*,err=900) irpt
+ irpt=(irpt-509)/10 - 2
+ if(irpt.lt.0) irpt=0
+ if(irpt.gt.7) irpt=7
+! 3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest
+! 3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX)
+ write(c77,1010) itu,n28a,n28b,ir,irpt,nexch,i3
+1010 format(b1,2b28.28,b1,b3.3,b13.13,b3.3)
+ endif
+ endif
+
+900 return
+end subroutine pack77_3var
+
+subroutine pack77_4var(nwords,w,i3,n3,c77,ntxhash)
+
+! Check Type 4 (One nonstandard call and one hashed call)
+! Example message: <WA9XYZ> PJ4/KA1ABC RR73 12 58 1 2 1 74
+
+ integer*8 n58
+ logical ok1,ok2,lhashit
+ character*13 w(19)
+ character*77 c77
+ character*13 call_1,call_2
+ character*11 c11
+ character*6 bcall_1,bcall_2
+ character*38 c
+ integer, intent(in) :: ntxhash
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+
+ iflip=0
+ i3=-1
+ if(nwords.eq.2 .or. nwords.eq.3) then
+ call_1=w(1)
+ if(call_1(1:1).eq.'<') call_1=w(1)(2:len(trim(w(1)))-1)
+ call_2=w(2)
+ if(call_2(1:1).eq.'<') call_2=w(2)(2:len(trim(w(2)))-1)
+ call chkcall(call_1,bcall_1,ok1)
+ call chkcall(call_2,bcall_2,ok2)
+ if(call_1.eq.bcall_1 .and. call_2.eq.bcall_2 .and. ok1 .and. ok2) go to 900
+ icq=0
+ if(trim(w(1)).eq.'CQ' .or. (ok1.and.ok2)) then
+ if(trim(w(1)).eq.'CQ' .and. len(trim(w(2))).le.4) go to 900
+ i3=4
+ n3=0
+ if(trim(w(1)).eq.'CQ') icq=1
+ endif
+
+ lhashit=.false.; if(ntxhash.eq.1) lhashit=.true.
+ if(icq.eq.1) then
+ iflip=0
+ n12=0
+ c11=adjustr(call_2(1:11))
+ call save_hash_txcallvar(w(2),n10,n12,n22,lhashit)
+ else if(w(1)(1:1).eq.'<') then
+ iflip=0
+ i3=4
+ call save_hash_txcallvar(w(1),n10,n12,n22,lhashit)
+ c11=adjustr(call_2(1:11))
+ else if(w(2)(1:1).eq.'<') then
+ iflip=1
+ i3=4
+ call save_hash_txcallvar(w(2),n10,n12,n22,lhashit)
+ c11=adjustr(call_1(1:11))
+ endif
+ n58=0
+ do i=1,11
+ n58=n58*38 + index(c,c11(i:i)) - 1
+ enddo
+ nrpt=0
+ if(trim(w(3)).eq.'RRR') nrpt=1
+ if(trim(w(3)).eq.'RR73') nrpt=2
+ if(trim(w(3)).eq.'73') nrpt=3
+ if(icq.eq.1) then
+ iflip=0
+ nrpt=0
+ endif
+ write(c77,1010) n12,n58,iflip,nrpt,icq,i3
+1010 format(b12.12,b58.58,b1,b2.2,b1,b3.3)
+ do i=1,77
+ if(c77(i:i).eq.'*') c77(i:i)='0' !### Clean up any illegal chars ###
+ enddo
+ endif
+
+900 return
+end subroutine pack77_4var
+
+subroutine pack77_5var(nwords,w,i3,n3,c77,ntxhash)
+
+! Pack a Type 0.2 message: EU VHF Contest mode
+! Example message: PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25
+! <PA3XYZ> <G4ABC/P> R 590003 IO91NP h10 h20 r1 s3 s12 g25
+
+ character*13 w(19),c13
+ character*77 c77
+ character*6 grid6
+ logical is_grid6,lhashit
+ integer, intent(in) :: ntxhash
+
+ is_grid6(grid6)=len(trim(grid6)).eq.6 .and. &
+ grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. &
+ grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. &
+ grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. &
+ grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. &
+ grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. &
+ grid6(6:6).ge.'A' .and. grid6(6:6).le.'X'
+
+ if(nwords.lt.4 .or. nwords.gt.5) return !nwords must be 4 or 5
+ if(w(1)(1:1).ne.'<' .or. w(2)(1:1).ne.'<') return !Both calls must be hashed
+ nx=-1
+ read(w(nwords-1),*,err=2) nx
+2 if(nx.lt.520001 .or. nx.gt.594095) return !Exchange between 520001 - 594095
+ if(.not.is_grid6(w(nwords)(1:6))) return !Last word must be a valid grid6
+
+! Type 0.2: <PA3XYZ> <G4ABC/P> R 590003 IO91NP h10 h20 r1 s3 s12 g25
+
+ i3=5
+ n3=0
+
+ lhashit=.false.; if(ntxhash.eq.1) lhashit=.true.
+ call save_hash_txcallvar(w(1),n10,n12,n22,lhashit)
+ i2=index(w(1),'>')
+ c13=w(1)(2:i2-1)
+ n12=ihashcall(c13,12)
+
+ call save_hash_txcallvar(w(2),n10a,n12a,n22,lhashit)
+ i2=index(w(2),'>')
+ c13=w(2)(2:i2-1)
+ n22=ihashcall(c13,22)
+
+ ir=0
+ if(w(3)(1:2).eq.'R ') ir=1
+ irpt=nx/10000 - 52
+ iserial=mod(nx,10000)
+ if(iserial.gt.2047) iserial=2047
+ grid6=w(nwords)(1:6)
+ j1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*24*24
+ j2=(ichar(grid6(2:2))-ichar('A'))*10*10*24*24
+ j3=(ichar(grid6(3:3))-ichar('0'))*10*24*24
+ j4=(ichar(grid6(4:4))-ichar('0'))*24*24
+ j5=(ichar(grid6(5:5))-ichar('A'))*24
+ j6=(ichar(grid6(6:6))-ichar('A'))
+ igrid6=j1+j2+j3+j4+j5+j6
+ write(c77,1010) n12,n22,ir,irpt,iserial,igrid6,i3
+1010 format(b12.12,b22.22,b1,b3.3,b11.11,b25.25,b3.3)
+
+ return
+end subroutine pack77_5var
+
+subroutine packtext77var(c13,c71)
+
+ character*13 c13,w
+ character*71 c71
+ character*42 c
+ character*1 qa(10),qb(10)
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/
+
+ call mp_short_init
+ qa=char(0)
+ w=adjustr(c13)
+ do i=1,13
+ j=index(c,w(i:i))-1
+ if(j.lt.0) j=0
+ call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9)
+ call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j
+ enddo
+
+ write(c71,1010) qa(2:10)
+1010 format(b7.7,8b8.8)
+
+ return
+end subroutine packtext77var
+
+subroutine unpacktext77var(c71,c13)
+
+ integer*1 ia(10)
+ character*1 qa(10),qb(10)
+ character*13 c13
+ character*71 c71
+ character*42 c
+ equivalence (qa,ia),(qb,ib)
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/
+
+ qa(1)=char(0)
+ read(c71,1010) qa(2:10)
+1010 format(b7.7,8b8.8)
+
+ do i=13,1,-1
+ call mp_short_div(qb,qa(2:10),9,42,ir)
+ c13(i:i)=c(ir+1:ir+1)
+ qa(2:10)=qb(1:9)
+ enddo
+
+ return
+end subroutine unpacktext77var
+
+subroutine mp_short_opsvar(w,u)
+ character*1 w(*),u(*)
+ integer i,ireg,j,n,ir,iv,ii1,ii2
+ character*1 creg(4)
+ save ii1,ii2
+ equivalence (ireg,creg)
+
+ entry mp_short_init
+ ireg=256*ichar('2')+ichar('1')
+ do j=1,4
+ if (creg(j).eq.'1') ii1=j
+ if (creg(j).eq.'2') ii2=j
+ enddo
+ return
+
+ entry mp_short_add(w,u,n,iv)
+ ireg=256*iv
+ do j=n,1,-1
+ ireg=ichar(u(j))+ichar(creg(ii2))
+ w(j+1)=creg(ii1)
+ enddo
+ w(1)=creg(ii2)
+ return
+
+ entry mp_short_mult(w,u,n,iv)
+ ireg=0
+ do j=n,1,-1
+ ireg=ichar(u(j))*iv+ichar(creg(ii2))
+ w(j+1)=creg(ii1)
+ enddo
+ w(1)=creg(ii2)
+ return
+
+ entry mp_short_div(w,u,n,iv,ir)
+ ir=0
+ do j=1,n
+ i=256*ir+ichar(u(j))
+ w(j)=char(i/iv)
+ ir=mod(i,iv)
+ enddo
+ return
+
+ return
+end subroutine mp_short_opsvar
+
+subroutine add_call_to_recent_callsvar(callsign,nthr)
+
+ character*13 callsign
+ logical ladd
+ integer, intent(in) :: nthr
+
+! only add if the callsign is not already on the list
+ ladd=.true.
+ do i=1,MAXRECENT-1 ! if callsign is at the end of the list add it again
+ if(recent_calls(i).eq.callsign) ladd=.false.
+ enddo
+
+ if(ladd) then
+ do i=MAXRECENT,2,-1
+ recent_calls(i)=recent_calls(i-1)
+ enddo
+ recent_calls(1)=callsign
+ endif
+
+! Make sure that callsign is hashed
+ call save_hash_callvar(callsign,nthr)
+
+ return
+end subroutine add_call_to_recent_callsvar
+
+subroutine to_grid4var(n,grid4,ok)
+ character*4 grid4
+ logical ok
+
+ ok=.false.
+ j1=n/(18*10*10)
+ if (j1.lt.0.or.j1.gt.17) goto 900
+ n=n-j1*18*10*10
+ j2=n/(10*10)
+ if (j2.lt.0.or.j2.gt.17) goto 900
+ n=n-j2*10*10
+ j3=n/10
+ if (j3.lt.0.or.j3.gt.9) goto 900
+ j4=n-j3*10
+ if (j4.lt.0.or.j4.gt.9) goto 900
+ grid4(1:1)=char(j1+ichar('A'))
+ grid4(2:2)=char(j2+ichar('A'))
+ grid4(3:3)=char(j3+ichar('0'))
+ grid4(4:4)=char(j4+ichar('0'))
+ ok=.true.
+
+900 return
+end subroutine to_grid4var
+
+subroutine to_grid6var(n,grid6,ok)
+ character*6 grid6
+ logical ok
+
+ ok=.false.
+ j1=n/(18*10*10*24*24)
+ if (j1.lt.0.or.j1.gt.17) goto 900
+ n=n-j1*18*10*10*24*24
+ j2=n/(10*10*24*24)
+ if (j2.lt.0.or.j2.gt.17) goto 900
+ n=n-j2*10*10*24*24
+ j3=n/(10*24*24)
+ if (j3.lt.0.or.j3.gt.9) goto 900
+ n=n-j3*10*24*24
+ j4=n/(24*24)
+ if (j4.lt.0.or.j4.gt.9) goto 900
+ n=n-j4*24*24
+ j5=n/24
+ if (j5.lt.0.or.j5.gt.23) goto 900
+ j6=n-j5*24
+ if (j6.lt.0.or.j6.gt.23) goto 900
+ grid6(1:1)=char(j1+ichar('A'))
+ grid6(2:2)=char(j2+ichar('A'))
+ grid6(3:3)=char(j3+ichar('0'))
+ grid6(4:4)=char(j4+ichar('0'))
+ grid6(5:5)=char(j5+ichar('A'))
+ grid6(6:6)=char(j6+ichar('A'))
+ ok=.true.
+
+900 return
+end subroutine to_grid6var
+
+subroutine to_gridvar(n,grid6,ok)
+ ! 4-, or 6-character grid
+ character*6 grid6
+ logical ok
+
+ ok=.false.
+ j1=n/(18*10*10*25*25)
+ if (j1.lt.0.or.j1.gt.17) goto 900
+ n=n-j1*18*10*10*25*25
+ j2=n/(10*10*25*25)
+ if (j2.lt.0.or.j2.gt.17) goto 900
+ n=n-j2*10*10*25*25
+ j3=n/(10*25*25)
+ if (j3.lt.0.or.j3.gt.9) goto 900
+ n=n-j3*10*25*25
+ j4=n/(25*25)
+ if (j4.lt.0.or.j4.gt.9) goto 900
+ n=n-j4*25*25
+ j5=n/25
+ if (j5.lt.0.or.j5.gt.24) goto 900
+ j6=n-j5*25
+ if (j6.lt.0.or.j6.gt.24) goto 900
+ grid6=''
+ grid6(1:1)=char(j1+ichar('A'))
+ grid6(2:2)=char(j2+ichar('A'))
+ grid6(3:3)=char(j3+ichar('0'))
+ grid6(4:4)=char(j4+ichar('0'))
+ if (j5.ne.24.or.j6.ne.24) then
+ grid6(5:5)=char(j5+ichar('A'))
+ grid6(6:6)=char(j6+ichar('A'))
+ endif
+ ok=.true.
+
+900 return
+end subroutine to_gridvar
+
+end module packjt77var
diff --git a/lib/ft8var/partint.f90 b/lib/ft8var/partint.f90 new file mode 100755 index 00000000..66395d11 --- /dev/null +++ b/lib/ft8var/partint.f90 @@ -0,0 +1,18 @@ +
+subroutine partint(ndelay,nutc)
+
+ use jt65_mod6
+ real rnd
+
+ numsamp=ndelay*1200
+ dd(numsamp+1:624000)=dd(1:(624000-numsamp))
+ do i=1,numsamp
+ call random_number(rnd)
+ dd(i)=10.0*rnd-5.
+ enddo
+ write(*,2) nutc,'partial loss of data','d'
+2 format(i4.4,2x,a20,21x,a1)
+ call flush(6)
+
+ return
+end subroutine partint
\ No newline at end of file diff --git a/lib/ft8var/partintft8.f90 b/lib/ft8var/partintft8.f90 new file mode 100755 index 00000000..be2f7006 --- /dev/null +++ b/lib/ft8var/partintft8.f90 @@ -0,0 +1,18 @@ +subroutine partintft8(ndelay,nutc)
+
+ use ft8_mod1, only : dd8
+ real rnd
+
+ if(ndelay.gt.120) ndelay=120
+ numsamp=nint(float(ndelay)*1200)
+ dd8(numsamp+1:180000)=dd8(1:(180000-numsamp))
+ do i=1,numsamp
+ call random_number(rnd)
+ dd8(i)=10.0*rnd-5.
+ enddo
+ write(*,2) nutc,'partial loss of data','d'
+2 format(i6.6,2x,a20,21x,a1)
+ call flush(6)
+
+ return
+end subroutine partintft8
\ No newline at end of file diff --git a/lib/ft8var/rms_augapvar.f90 b/lib/ft8var/rms_augapvar.f90 new file mode 100755 index 00000000..c845900f --- /dev/null +++ b/lib/ft8var/rms_augapvar.f90 @@ -0,0 +1,42 @@ +
+subroutine rms_augapvar(nutc,lowrms)
+
+ use jt65_mod6, only : dd
+
+ logical lowrms,baddatavar
+
+ rms1=sqrt(dot_product(dd(100000:100099),dd(100000:100099))/100.0)
+ rms2=sqrt(dot_product(dd(200000:200099),dd(200000:200099))/100.0)
+ rms3=sqrt(dot_product(dd(300000:300099),dd(300000:300099))/100.0)
+ rms4=sqrt(dot_product(dd(400000:400099),dd(400000:400099))/100.0)
+ rms5=sqrt(dot_product(dd(500000:500099),dd(500000:500099))/100.0)
+ rms=(rms1+rms2+rms3+rms4+rms5)/5.0
+ if(rms.lt.2.0) then
+ write(*,1016) nutc,'input signal low rms','d'
+1016 format(i4.4,2x,a20,19x,a1)
+ call flush(6)
+ lowrms=.true.
+ return
+ endif
+
+ if(baddatavar()) then
+ write(*,1017) nutc,'audio gap detected','d'
+1017 format(i4.4,2x,a18,21x,a1)
+ call flush(6)
+
+ j=0
+ do i=1,490
+ sq=0.
+ do n=1,1200,60
+ j=j+60
+ x=dd(j)
+ sq=sq + abs(x)
+ enddo
+ if(sq.lt.1.0) then
+ dd(j)=1.0; dd(j-600)=1.0
+ endif
+ enddo
+ endif
+
+ return
+end subroutine rms_augapvar
\ No newline at end of file diff --git a/lib/ft8var/searchcallsvar.f90 b/lib/ft8var/searchcallsvar.f90 new file mode 100755 index 00000000..37a1c323 --- /dev/null +++ b/lib/ft8var/searchcallsvar.f90 @@ -0,0 +1,83 @@ +
+subroutine searchcallsvar(callsign1,callsign2,lfound)
+
+ use jt65_mod9, only : ncall0c,ncalld,ncallef,ncallgh,ncalli,ncallj,ncallk,ncalllm,ncalln,ncallo,ncallpq,ncallr, &
+ ncallst,ncalluv,ncallw,ncallxz,call0c,calld,callef,callgh,calli,callj,callk,calllm,calln,callo, &
+ callpq,callr,callst,calluv,callw,callxz,ldbvalid ! callsign DB in memory
+ character*12 callsign0,callsign1,callsign2
+ logical(1) lfound
+
+ if(.not.ldbvalid) then; lfound=.true.; return; endif ! bail out
+
+ nlencall1=len_trim(callsign1); nlencall2=len_trim(callsign2)
+ if(nlencall1.gt.7 .and. callsign2.eq." ") then; lfound=.true.; return; endif
+ if(nlencall2.gt.7) callsign2=" " ! we can not put in ALLCALL all special callsign0s in advance
+ ncycles=2; if(callsign2.eq." ") ncycles=1
+ do j=1,ncycles
+ if(j.eq.1) then; callsign0=callsign1; else; callsign0=callsign2; endif
+ if(callsign0.eq."TU;") cycle
+ if(callsign0(1:1).lt."N") then
+ if(callsign0(1:1).lt."I") then
+ if(callsign0(1:1).lt."E") then
+ if(callsign0(1:1).lt."D") then
+ do i=1,ncall0c; if(call0c(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncalld; if(calld(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ else
+ if(callsign0(1:1).lt."G") then
+ do i=1,ncallef; if(callef(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncallgh; if(callgh(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ endif
+ else
+ if(callsign0(1:1).lt."K") then
+ if(callsign0(1:1).lt."J") then
+ do i=1,ncalli; if(calli(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncallj; if(callj(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ else
+ if(callsign0(1:1).lt."L") then
+ do i=1,ncallk; if(callk(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncalllm; if(calllm(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ endif
+ endif
+ else
+ if(callsign0(1:1).lt."S") then
+ if(callsign0(1:1).lt."P") then
+ if(callsign0(1:1).lt."O") then
+ do i=1,ncalln; if(calln(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncallo; if(callo(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ else
+ if(callsign0(1:1).lt."R") then
+ do i=1,ncallpq; if(callpq(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncallr; if(callr(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ endif
+ else
+ if(callsign0(1:1).lt."W") then
+ if(callsign0(1:1).lt."U") then
+ do i=1,ncallst; if(callst(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncalluv; if(calluv(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ else
+ if(callsign0(1:1).lt."X") then
+ do i=1,ncallw; if(callw(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ else
+ do i=1,ncallxz; if(callxz(i).eq.callsign0) then; lfound=.true.; return; endif; enddo
+ endif
+ endif
+ endif
+ endif
+ enddo
+! print *,"blocked ",callsign1,callsign2
+ return
+end subroutine searchcallsvar
diff --git a/lib/ft8var/subtractft8var.f90 b/lib/ft8var/subtractft8var.f90 new file mode 100755 index 00000000..5c7ba211 --- /dev/null +++ b/lib/ft8var/subtractft8var.f90 @@ -0,0 +1,41 @@ +subroutine subtractft8var(itone,f0,dt)
+
+! Subtract an ft8 signal
+!
+! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t))
+! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) )
+! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ]
+! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt}
+
+ use ft8_mod1, only : dd8,cw,NFILT1,NFILT2,endcorr
+! NMAX=15*12000,NFFT=15*12000,NFRAME=1920*79
+ parameter (NFFT=180000,NMAX=180000,NFRAME=151680)
+ complex cref(nframe),cfilt(nmax)
+ integer itone(79)
+ save cfilt
+ !$omp threadprivate(cfilt)
+
+ nstart=dt*12000+1
+ call gen_ft8wavevar(itone,79,1920,2.0,12000.0,f0,cref,xjunk,1,NFRAME)
+ do i=1,nframe
+ id=nstart-1+i
+ if(id.ge.1.and.id.le.NMAX) then
+ cfilt(i)=dd8(id)*conjg(cref(i))
+ else
+ cfilt(i)=0.0
+ endif
+ enddo
+ cfilt(nframe+1:)=0.0
+ call four2avar(cfilt,nfft,1,-1,1)
+ cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft)
+ call four2avar(cfilt,nfft,1,1,1)
+ cfilt(1:NFILT1/2+1)=cfilt(1:NFILT1/2+1)*endcorr
+ cfilt(nframe:nframe-NFILT1/2:-1)=cfilt(nframe:nframe-NFILT1/2:-1)*endcorr
+ do i=1,nframe
+ j=nstart+i-1
+ if(j.ge.1 .and. j.le.NMAX) dd8(j)=dd8(j)-2*REAL(cfilt(i)*cref(i))
+ enddo
+!!!$omp flush(dd8) ! makes no difference in number of decoded messages
+
+ return
+end subroutine subtractft8var
diff --git a/lib/ft8var/sync8dvar.f90 b/lib/ft8var/sync8dvar.f90 new file mode 100755 index 00000000..19e8e35a --- /dev/null +++ b/lib/ft8var/sync8dvar.f90 @@ -0,0 +1,123 @@ +subroutine sync8dvar(cd0,i0,ctwk,itwk,sync,ipass,lastsync,iqso,lcq,lcallsstd,lcqcand)
+
+! Compute sync power for a complex, downsampled FT8 signal.
+ use ft8_mod1, only : csync,csynce,csyncsd,csyncsdcq,csynccq
+
+ complex, intent(in) :: cd0(-800:4000),ctwk(32)
+ complex csync1(0:18,32),csync2(32),z1,z2,z3,z4,zt1(0:6),zt2(0:6),zt3(0:6),zt4(0:7),zt5(0:18), &
+ z11(224),z22(224),z33(224)
+ real sync1(0:20)!,sync2(0:20)
+ integer, intent(in) :: i0,ipass,iqso
+ logical(1), intent(in) :: lcq,lcallsstd,lcqcand
+ logical(1) lastsync
+
+ sync=0.; sync1=0.; zt1=0.; zt2=0.; zt3=0.; z11=0.; z22=0.; z33=0.!; sync2=0.
+ k=1
+ do i=0,6 ! Sum over 7 Costas frequencies and three Costas arrays
+ i1=i0+i*32; i2=i1+1152; i3=i1+2304 ! +36*32, +72*32
+ csync2=csync(i,1:32)
+ if(itwk.eq.1) csync2=ctwk*csync2 !Tweak the frequency
+ z11(k:k+31)=cd0(i1:i1+31)*conjg(csync2); z22(k:k+31)=cd0(i2:i2+31)*conjg(csync2)
+ z33(k:k+31)=cd0(i3:i3+31)*conjg(csync2)
+ zt1(i)=sum(z11(k:k+31)); zt2(i)=sum(z22(k:k+31)); zt3(i)=sum(z33(k:k+31))
+ k=k+32
+ enddo
+ if(ipass.eq.1 .or. ipass.eq.5 .or. ipass.eq.9) then
+ if(.not.lastsync) then
+ do i=0,6
+ sync1(i) = SQRT(real(zt1(i))**2 + aimag(zt1(i))**2)
+ sync1(i+7) = SQRT(real(zt2(i))**2 + aimag(zt2(i))**2)
+ sync1(i+14) = SQRT(real(zt3(i))**2 + aimag(zt3(i))**2)
+ enddo
+ sync=sum(sync1)
+ else
+ do i=0,6
+ sync = sync + real(zt1(i))**2 + aimag(zt1(i))**2 + real(zt2(i))**2 + aimag(zt2(i))**2 + real(zt3(i))**2 + &
+ aimag(zt3(i))**2
+ enddo
+ endif
+ else if(ipass.eq.2 .or. ipass.eq.6 .or. ipass.eq.7) then
+ if(.not.lastsync) then
+ do i=0,6
+ sync1(i) = real(zt1(i))**2 + aimag(zt1(i))**2
+ sync1(i+7) = real(zt2(i))**2 + aimag(zt2(i))**2
+ sync1(i+14) = real(zt3(i))**2 + aimag(zt3(i))**2
+ enddo
+ sync=sum(sync1)
+ else
+ do i=0,6
+ sync = sync + real(zt1(i))**2 + aimag(zt1(i))**2 + real(zt2(i))**2 + aimag(zt2(i))**2 + real(zt3(i))**2 + &
+ aimag(zt3(i))**2
+ enddo
+ endif
+ else ! if(ipass.eq.3 .or. ipass.eq.4 .or. ipass.eq.8) then
+ do i=0,6
+ if(i.lt.6) then
+ z1=(zt1(i)+zt1(i+1))/2; z2=(zt2(i)+zt2(i+1))/2; z3=(zt3(i)+zt3(i+1))/2 ! use i=5 z values for i=6
+ endif
+ if(.not.lastsync) then
+ sync = sync + abs(real(z1)) + abs(aimag(z1)) + abs(real(z2)) + abs(aimag(z2)) + abs(real(z3)) + abs(aimag(z3))
+ else
+ sync = sync + real(z1)**2 + aimag(z1)**2 + real(z2)**2 + aimag(z2)**2 + real(z3)**2 + aimag(z3)**2
+ endif
+ enddo
+ endif
+
+ if(itwk.eq.1 .and. lcqcand .and. iqso.eq.1) then
+ zt4=0.
+ do i=0,7
+ csync2=csynccq(i,1:32); csync2=ctwk*csync2 !Tweak the frequency
+ i4=i0+(i+7)*32; zt4(i)=sum(cd0(i4:i4+31)*conjg(csync2))
+ enddo
+ do i=0,7
+ if(ipass.eq.3 .or. ipass.eq.4 .or. ipass.eq.8) then
+ if(i.lt.7) z4=(zt4(i)+zt4(i+1))/2 ! use i=6 z4 value for i=7
+ else
+ z4=zt4(i)
+ endif
+ if(ipass.eq.1 .or. ipass.eq.5 .or. ipass.eq.9) then; sync = sync + SQRT(real(z4)**2 + aimag(z4)**2)
+ else if(ipass.eq.2 .or. ipass.eq.6 .or. ipass.eq.7) then; sync = sync + real(z4)**2 + aimag(z4)**2
+ else if(ipass.eq.3 .or. ipass.eq.4 .or. ipass.eq.8) then; sync = sync + abs(real(z4)) + abs(aimag(z4))
+ endif
+ enddo
+ endif
+
+ if(.not.lastsync) then
+ if(iqso.gt.1 .and. iqso.lt.4 .and. lcallsstd) csync1=csynce; if(iqso.eq.4 .and. .not.lcq) csync1=csyncsd
+
+ if((iqso.eq.4 .and. .not.lcq) .or. ((iqso.eq.2 .or. iqso.eq.3) .and. lcallsstd)) then
+ zt5=0.
+ do i=0,18
+ csync2=csync1(i,1:32)
+ if(itwk.eq.1) csync2=ctwk*csync2 !Tweak the frequency
+ i4=i0+(i+7)*32; zt5(i)=sum(cd0(i4:i4+31)*conjg(csync2))
+ enddo
+ do i=0,18
+ if(ipass.eq.2 .or. ipass.eq.6 .or. ipass.eq.7) then
+ if(i.lt.18) z4=(zt5(i)+zt5(i+1))/2 ! use i=17 z4 value for i=18
+ else
+ z4=zt5(i)
+ endif
+ if(ipass.eq.1 .or. ipass.eq.5 .or. ipass.eq.9) then; sync = sync + SQRT(real(z4)**2 + aimag(z4)**2)
+ else if(ipass.eq.2 .or. ipass.eq.6 .or. ipass.eq.7) then; sync = sync + real(z4)**2 + aimag(z4)**2
+ else if(ipass.eq.3 .or. ipass.eq.4 .or. ipass.eq.8) then; sync = sync + abs(real(z4)) + abs(aimag(z4))
+ endif
+ enddo
+ endif
+
+ if(iqso.eq.4 .and. lcq) then
+ do i=0,57
+ csync2=csyncsdcq(i,1:32)
+ if(itwk.eq.1) csync2=ctwk*csync2 !Tweak the frequency
+ z4=0.; if(i.lt.29) then; k=i+7; else; k=i+14; endif
+ i4=i0+k*32; z4=sum(cd0(i4:i4+31)*conjg(csync2))
+ if(ipass.eq.1 .or. ipass.eq.5 .or. ipass.eq.9) then; sync = sync + SQRT(real(z4)**2 + aimag(z4)**2)
+ else if(ipass.eq.2 .or. ipass.eq.6 .or. ipass.eq.7) then; sync = sync + real(z4)**2 + aimag(z4)**2
+ else if(ipass.eq.3 .or. ipass.eq.4 .or. ipass.eq.8) then; sync = sync + abs(real(z4)) + abs(aimag(z4))
+ endif
+ enddo
+ endif
+ endif
+
+ return
+end subroutine sync8dvar
diff --git a/lib/ft8var/sync8var.f90 b/lib/ft8var/sync8var.f90 new file mode 100755 index 00000000..f145c2e6 --- /dev/null +++ b/lib/ft8var/sync8var.f90 @@ -0,0 +1,285 @@ +subroutine sync8var(nfa,nfb,syncmin,nfqso,candidate,ncand,jzb,jzt,ipass,lqsothread,ncandthin,ndtcenter)
+
+ use ft8_mod1, only : dd8,windowx,facx,icos7,lagcc,lagccbail,nfawide,nfbwide
+ include 'ft8_params.f90'
+ complex cx(0:NH1)
+ real s(NH1,NHSYM),x(NFFT1),sync2d(NH1,jzb:jzt),red(NH1),candidate0(5,450),candidate(4,460),tall(30),freq,rcandthin,dtcenter
+ integer jpeak(NH1),indx(NH1),ii(1)
+ integer, intent(in) :: nfa,nfb,nfqso,jzb,jzt,ipass,ncandthin,ndtcenter
+ logical(1) syncq(NH1,jzb:jzt),redcq(NH1),lcq,lcq2,lpass1,lpass2
+ logical(1), intent(in) :: lqsothread
+ equivalence (x,cx)
+
+! Compute symbol spectra, stepping by NSTEP steps.
+ tstep=0.04 ! NSTEP/12000.0
+ df=3.125 ! 12000.0/NFFT1 , Hz
+ syncq=.false.; redcq=.false.; candidate(4,:)=0.
+ rcandthin=ncandthin/100.;
+ dtcenter=ndtcenter/100.
+
+ if(ipass.eq.1 .or. ipass.eq.4 .or. ipass.eq.7) then
+ do j=1,NHSYM
+ ia=(j-1)*NSTEP + 1
+ ib=ia+NSPS-1
+ x(1:759)=0.
+ if(j.ne.1) then; x(760:960)=dd8(ia-201:ia-1)*windowx(200:0:-1); else; x(760:960)=0.; endif
+ x(961:2880)=facx*dd8(ia:ib); x(961)=x(961)*1.9; x(2880)=x(2880)*1.9
+ if(j.ne.NHSYM) then; x(2881:3081)=dd8(ib+1:ib+201)*windowx; else; x(2881:3081)=0.; endif
+ x(3082:)=0.
+ call four2avar(cx,NFFT1,1,-1,0) !r2c FFT
+ do i=1,NH1
+ s(i,j)=SQRT(real(cx(i))**2 + aimag(cx(i))**2)
+ enddo
+ enddo
+ endif
+ if(ipass.eq.2 .or. ipass.eq.5 .or. ipass.eq.8) then
+ do j=1,NHSYM
+ ia=(j-1)*NSTEP + 1
+ ib=ia+NSPS-1
+ x(1:759)=0.
+ if(j.ne.1) then; x(760:960)=dd8(ia-201:ia-1)*windowx(200:0:-1); else; x(760:960)=0.; endif
+ x(961:2880)=facx*dd8(ia:ib); x(961)=x(961)*1.9; x(2880)=x(2880)*1.9
+ if(j.ne.NHSYM) then; x(2881:3081)=dd8(ib+1:ib+201)*windowx; else; x(2881:3081)=0.; endif
+ x(3082:)=0.
+ call four2avar(cx,NFFT1,1,-1,0) !r2c FFT
+ do i=1,NH1
+ s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
+ enddo
+ enddo
+ endif
+ if(ipass.eq.3 .or. ipass.eq.6 .or. ipass.eq.9) then
+ do j=1,NHSYM
+ ia=(j-1)*NSTEP + 1
+ ib=ia+NSPS-1
+ x(1:759)=0.
+ if(j.ne.1) then; x(760:960)=dd8(ia-201:ia-1)*windowx(200:0:-1); else; x(760:960)=0.; endif
+ x(961:2880)=facx*dd8(ia:ib); x(961)=x(961)*1.9; x(2880)=x(2880)*1.9
+ if(j.ne.NHSYM) then; x(2881:3081)=dd8(ib+1:ib+201)*windowx; else; x(2881:3081)=0.; endif
+ x(3082:)=0.
+ call four2avar(cx,NFFT1,1,-1,0) !r2c FFT
+ do i=1,NH1
+ s(i,j)=abs(real(cx(i))) + abs(aimag(cx(i)))
+ enddo
+ enddo
+ endif
+
+ ia=max(1,nint(nfa/df)); ib=max(1,nint(nfb/df)); iaw=max(1,nint(nfawide/df)); ibw=max(1,nint(nfbwide/df))
+ nssy=4 ! NSPS/NSTEP ! # steps per symbol
+ nssy36=144 ! nssy*36
+ nssy72=288 ! nssy*72
+ nfos=2 ! NFFT1/NSPS ! # frequency bin oversampling factor
+ jstrt=12.5 ! 0.5/tstep
+
+ if(lagcc .and. .not.lagccbail) then
+ nfos6=12 ! nfos*6
+ do j=jzb,jzt
+ do i=iaw,ibw
+ ta=0.; tb=0.; tc=0.
+ do n=0,6
+ k=j+jstrt+nssy*n
+ if(k.gt.0) then
+ ta=s(i+nfos*icos7(n),k)
+ if(ta.gt.1e-9) then; tall(n+1)=ta*6.0/(sum(s(i:i+nfos6:nfos,k))-ta); else; tall(n+1)=0.; endif
+ endif
+ k36=k+nssy36
+ if(k36.gt.0 .and. k36.le.NHSYM) then
+ tb=s(i+nfos*icos7(n),k36)
+ if(tb.gt.1e-9) then; tall(n+17)=tb*6.0/(sum(s(i:i+nfos6:nfos,k36))-tb); else; tall(n+17)=0.; endif
+ endif
+ k72=k+nssy72
+ if(k72.le.NHSYM) then
+ tc=s(i+nfos*icos7(n),k72)
+ if(tc.gt.1e-9) then; tall(n+24)=tc*6.0/(sum(s(i:i+nfos6:nfos,k72))-tc); else; tall(n+24)=0.; endif
+ endif
+ enddo
+ lcq=.false.
+ if(ipass.gt.1) then
+ do n=7,15
+ k=j+jstrt+nssy*n
+ if(k.gt.0) then
+ if(n.lt.15) then
+ tall(n+1)=s(i,k)*6.0/(sum(s(i:i+nfos6:nfos,k))-s(i,k))
+ else
+ tall(n+1)=s(i+2,k)*6.0/(sum(s(i:i+nfos6:nfos,k))-s(i+2,k))
+ endif
+ endif
+ enddo
+ sya=sum(tall(1:7)); sycq=sum(tall(8:16)); sybc=sum(tall(17:30))
+ sy1=(sya+sycq+sybc)/30.; sy2=(sya+sybc)/21.; sync_abc=max(sy1,sy2)
+ sy1=(sycq+sybc)/23.; sy2=(sybc)/14.; sync_bc=max(sy1,sy2); if(sy1.gt.sy2) lcq=.true.
+ else
+ sybc=sum(tall(17:30)); sync_abc=sum(tall(1:7))+sybc; sync_bc=sybc/14.; sync_abc=sync_abc/21.
+ endif
+ sync2d(i,j)=max(sync_abc,sync_bc); if(lcq) syncq(i,j)=.true.
+ enddo
+ enddo
+ else
+! nfos6=15 ! 16i spec bw -1
+ nfos6=16
+ do j=jzb,jzt
+ do i=iaw,ibw
+ ta=0.; tb=0.; tc=0.; tcq=0.; t0a=0.; t0b=0.; t0c=0.; t0cq=0.
+ do n=0,6
+ k=j+jstrt+nssy*n
+ if(k.gt.0) then; ta=ta + s(i+nfos*icos7(n),k); t0a=t0a + sum(s(i:i+nfos6,k)) - s(i+nfos*icos7(n)+1,k); endif
+ k36=k+nssy36
+ if(k36.gt.0 .and. k36.le.NHSYM) then
+ tb=tb + s(i+nfos*icos7(n),k36); t0b=t0b + sum(s(i:i+nfos6,k36)) - s(i+nfos*icos7(n)+1,k36)
+ endif
+ k72=k+nssy72
+ if(k72.le.NHSYM) then
+ tc=tc + s(i+nfos*icos7(n),k72)
+ t0c=t0c + sum(s(i:i+nfos6,k72)) - s(i+nfos*icos7(n)+1,k72)
+ endif
+ enddo
+ do n=7,15
+ k=j+jstrt+nssy*n
+ if(k.ge.1) then
+ if(n.lt.15) then; tcq=tcq + s(i,k); t0cq=t0cq + sum(s(i:i+nfos6,k)) - s(i,k+1)
+ else; tcq=tcq + s(i+2,k); t0cq=t0cq + sum(s(i:i+nfos6,k)) - s(i,k+3)
+ endif
+ endif
+ enddo
+ t1=ta+tb+tc; t01=t0a+t0b+t0c; t2=t1+tcq; t02=t01+t0cq
+ t01=(t01-t1*2)/42.0; if(t01.lt.1e-8) t01=1.0; t02=(t02-t2*2)/60.0; if(t02.lt.1e-8) t02=1.0 ! safe division
+ sync01=t1/(7.0*t01); sync02=(t1/7.0 + tcq/9.0)/t02; syncf=max(sync01,sync02)
+ lcq=.false.; if(sync02.gt.sync01) lcq=.true.
+ t1=tb+tc; t01=t0b+t0c; t2=t1+tcq; t02=t01+t0cq
+ t01=(t01-t1*2)/28.0; if(t01.lt.1e-8) t01=1.0; t02=(t02-t2*2)/46.0; if(t02.lt.1e-8) t02=1.0 ! safe division
+ sync01=t1/(7.0*t01); sync02=(t1/7.0 + tcq/9.0)/t02; syncs=max(sync01,sync02)
+ lcq2=.false.; if(sync02.gt.sync01) lcq2=.true.
+ sync2d(i,j)=max(syncf,syncs)
+ if(syncf.gt.syncs) then; if(lcq) syncq(i,j)=.true.; else; if(lcq2) syncq(i,j)=.true.; endif
+ enddo
+ enddo
+ endif
+
+ red=0.
+ do i=iaw,ibw
+ ii=maxloc(sync2d(i,jzb:jzt)) - 1 + jzb
+ j0=ii(1)
+ jpeak(i)=j0
+ red(i)=sync2d(i,j0); if(syncq(i,j0)) redcq(i)=.true.
+! write(52,3052) i*df,red(i),db(red(i))
+!3052 format(3f12.3)
+ enddo
+
+ iz=ibw-iaw+1
+ call indexx(red(iaw:ibw),iz,indx)
+ ibase=indx(max(1,nint(0.40*iz))) - 1 + iaw ! max is workaround to prevent indx getting out of bounds
+ base=red(ibase)
+ if(base.lt.1e-8) base=1.0 ! safe division
+ red=red/base
+
+ candidate0=0.; k=0; iz=ib-ia+1; lpass1=.false.; lpass2=.false.
+ if(rcandthin.lt.0.99) then
+ if(ipass.eq.1 .or. ipass.eq.4 .or. ipass.eq.7) then; lpass1=.true.
+ else if(ipass.eq.2 .or. ipass.eq.5 .or. ipass.eq.8) then; lpass2=.true.
+ endif
+ endif
+ call indexx(red(ia:ib),iz,indx)
+ do i=1,iz
+ n=ia + indx(iz+1-i) - 1
+ freq=n*df
+ if(abs(freq-nfqso).gt.3.0) then
+ if (red(n).lt.syncmin) cycle
+ else
+ if (red(n).lt.1.1) cycle
+ endif
+ if(jpeak(n).lt.-49 .or. jpeak(n).gt.76) cycle
+ if(k.lt.450) then; k=k+1; else; exit; endif
+! being sorted by sync
+ candidate0(1,k)=freq
+ candidate0(2,k)=(jpeak(n)-1)*tstep
+ candidate0(3,k)=red(n)
+ if(rcandthin.lt.0.99) then ! candidate thinning option
+ if(lpass2) then
+ candidate0(5,k)=candidate0(3,k)/(abs(candidate0(2,k)-dtcenter)+1.0)**2
+ else
+ candidate0(5,k)=candidate0(3,k)/(abs(candidate0(2,k)-dtcenter)+1.0)
+ endif
+ endif
+ if(redcq(n)) candidate0(4,k)=2.
+ enddo
+ ncand=k
+
+ fdif0=4.0;
+ xdtdelta=0.0
+! save sync only to the best of near-dupe freqs
+ do i=1,ncand
+ if(i.ge.2) then
+ do j=1,i-1
+ fdiff=abs(candidate0(1,i)-candidate0(1,j))
+ xdtdelta=abs(candidate0(2,i)-candidate0(2,j))
+ if(fdiff.lt.fdif0 .and. abs(candidate0(1,i)-nfqso).gt.3.0) then
+ if(xdtdelta.lt.0.1) then
+ if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0.
+ if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0.
+ endif
+ endif
+ enddo
+! write(*,3001) i,candidate0(1,i-1),candidate0(1,i),candidate0(3,i-1), &
+! candidate0(3,i)
+!3001 format(i2,4f8.1)
+ endif
+ enddo
+
+! Sort by sync
+! call indexx(candidate0(3,1:ncand),ncand,indx)
+ if(rcandthin.gt.0.99) then; call indexx(candidate0(3,1:ncand),ncand,indx)
+! sort by sync value with DT weight
+ else; call indexx(candidate0(5,1:ncand),ncand,indx)
+ endif
+! Sort by frequency
+! call indexx(candidate0(1,1:ncand),ncand,indx)
+
+ k=1; ncandfqso=0
+!Put nfqso at top of list and apply lowest sync threshold for nfqso
+ fprev=5004.
+ do i=ncand,1,-1
+ j=indx(i)
+ if(abs(candidate0(1,j)-nfqso).le.3.0 .and. candidate0(3,j).ge.1.1 .and. abs(candidate0(1,j)-fprev).gt.3.0) then
+ candidate(1,k)=candidate0(1,j); candidate(2,k)=candidate0(2,j)
+ candidate(3,k)=candidate0(3,j); candidate(4,k)=candidate0(4,j)
+ fprev=candidate0(1,j)
+ k=k+1; ncandfqso=ncandfqso+1
+ endif
+ enddo
+
+!put virtual candidates for FT8Svar decoder
+ if(lqsothread) then
+ candidate(1,k)=float(nfqso)
+ candidate(2,k)=5.0 ! xdt
+ candidate(3,k)=0.0 ! sync
+ k=k+1; ncandfqso=ncandfqso+1
+ candidate(1,k)=float(nfqso)
+ candidate(2,k)=-5.0
+ candidate(3,k)=0.0
+ k=k+1; ncandfqso=ncandfqso+1
+ endif
+
+ do i=ncand,1,-1
+ j=indx(i)
+ if(abs(candidate0(1,j)-nfqso).gt.3.0) then; syncmin1=syncmin; else; syncmin1=1.1; endif
+ if(candidate0(3,j) .ge. syncmin1) then
+ candidate(1,k)=candidate0(1,j); candidate(2,k)=candidate0(2,j)
+ candidate(3,k)=candidate0(3,j); candidate(4,k)=candidate0(4,j)
+ k=k+1
+ if(k.gt.460) exit
+ endif
+ enddo
+ ncand=k-1
+ if(ncand-ncandfqso.gt.1 .and. rcandthin.lt.0.99) then
+! applying decoding pass weight factor, derived from number of candidates in each pass
+ if(lpass1) then; rcandthin=min(rcandthin*1.27,1.0)
+ else if(lpass2) then
+ if(rcandthin.gt.0.79) then; rcandthin=rcandthin**2
+ else; rcandthin=rcandthin*0.79
+ endif
+ else; rcandthin=min(rcandthin*5.0,1.0) ! ipass 3,6,9
+ endif
+ ncand=ncandfqso+nint((ncand-ncandfqso)*rcandthin)
+ endif
+
+ return
+end subroutine sync8var
diff --git a/lib/ft8var/syncdist.f90 b/lib/ft8var/syncdist.f90 new file mode 100755 index 00000000..ff40754b --- /dev/null +++ b/lib/ft8var/syncdist.f90 @@ -0,0 +1,37 @@ +ip=maxloc(s81)
+if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(1)=nsmax(1)+1
+else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(2)=nsmax(2)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(3)=nsmax(3)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(4)=nsmax(4)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(5)=nsmax(5)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(6)=nsmax(6)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) then
+ nsmax(7)=nsmax(7)+1
+ else
+ s81(ip(1)-1)=0.; ip=maxloc(s81)
+ if(icos7(k-1).eq.(ip(1)-1)) nsmax(8)=nsmax(8)+1
+ endif
+ endif
+ endif
+ endif
+ endif
+ endif
+endif
diff --git a/lib/ft8var/tone8.f90 b/lib/ft8var/tone8.f90 new file mode 100755 index 00000000..92e5589a --- /dev/null +++ b/lib/ft8var/tone8.f90 @@ -0,0 +1,140 @@ +subroutine tone8(lmycallstd,lhiscallstd)
+
+ use ft8_mod1, only : itone56,idtone56,msg,csynce,mycall,hiscall,idtonecqdxcns,idtonedxcns73,mybcall,hisbcall,lhound, &
+ idtonefox73,idtonespec
+ complex csig0(151680)
+ character msg37*37,msgsent37*37,mycall14*14,hiscall14*14
+ character*4 rpt(56)
+ integer itone(79),itone1(79)
+ integer*1 msgbits(77)
+ logical(1), intent(in) :: lmycallstd,lhiscallstd
+
+ data rpt/'-01 ','-02 ','-03 ','-04 ','-05 ','-06 ','-07 ','-08 ','-09 ','-10 ', &
+ '-11 ','-12 ','-13 ','-14 ','-15 ','-16 ','-17 ','-18 ','-19 ','-20 ', &
+ '-21 ','-22 ','-23 ','-24 ','-25 ','-26 ','R-01','R-02','R-03','R-04', &
+ 'R-05','R-06','R-07','R-08','R-09','R-10','R-11','R-12','R-13','R-14', &
+ 'R-15','R-16','R-17','R-18','R-19','R-20','R-21','R-22','R-23','R-24', &
+ 'R-25','R-26','AA00','RRR ','RR73','73 '/
+
+! taken from ft8_mod1
+! integer itone56(56,79),idtone56(56,58)
+! character*37 msg(56)
+
+ if(lhound .and. len_trim(mybcall).gt.2 .and. len_trim(hisbcall).gt.2) then
+ msg37=''; msg37=trim(mybcall)//' '//trim(hisbcall)//' RR73'
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtonefox73(1:29)=itone(8:36)
+ idtonefox73(30:58)=itone(44:72)
+ msg37=''; msg37=trim(mybcall)//' RR73; '//trim(mybcall)//' <'//trim(hiscall)//'> -12'
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtonespec(1:29)=itone(8:36)
+ idtonespec(30:58)=itone(44:72)
+ endif
+
+ if(.not.lhiscallstd .and. len(trim(hiscall)).gt.2) then
+ msg37=''; msg37='CQ '//trim(hiscall)
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtonecqdxcns(1:29)=itone(8:36)
+ idtonecqdxcns(30:58)=itone(44:72)
+ msg37=''; msg37='<AA1AAA> '//trim(hiscall)//' 73'
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtonedxcns73(1:29)=itone(8:36)
+ idtonedxcns73(30:58)=itone(44:72)
+ endif
+
+ if(.not.lhiscallstd .and. .not.lmycallstd) return ! we do not support such message in FT8v2
+ if(.not.lhiscallstd .or. .not.lmycallstd) then
+ mycall14=' '; mycall14='<'//trim(mycall)//'>'
+ hiscall14=' '; hiscall14='<'//trim(hiscall)//'>'
+ endif
+
+ if(lhiscallstd .and. lmycallstd) then
+ do i=1,56
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall)//' '//trim(rpt(i))
+ msg(i)=msg37
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ if(i.eq.1) itone1=itone
+ idtone56(i,1:29)=itone(8:36)
+ idtone56(i,30:58)=itone(44:72)
+ itone56(i,1:79)=itone(1:79)
+ enddo
+ go to 2
+ endif
+
+ if(.not.lhiscallstd .and. lmycallstd) then
+ do i=1,52
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall14)//' '//trim(rpt(i))
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ if(i.eq.1) itone1=itone
+ idtone56(i,1:29)=itone(8:36)
+ idtone56(i,30:58)=itone(44:72)
+ itone56(i,1:79)=itone(1:79)
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall)//' '//trim(rpt(i))
+ msg(i)=msg37
+ enddo
+ do i=54,56
+ msg37=''; msg37=trim(mycall14)//' '//trim(hiscall)//' '//trim(rpt(i))
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtone56(i,1:29)=itone(8:36)
+ idtone56(i,30:58)=itone(44:72)
+ itone56(i,1:79)=itone(1:79)
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall)//' '//trim(rpt(i))
+ msg(i)=msg37
+ enddo
+ msg37=''; msg37=trim(mycall14)//' '//trim(hiscall)
+ msg(53)=msg37
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtone56(53,1:29)=itone(8:36)
+ idtone56(53,30:58)=itone(44:72)
+ itone56(53,1:79)=itone(1:79)
+ go to 2
+ endif
+
+ if(lhiscallstd .and. .not.lmycallstd) then
+ do i=1,52
+ msg37=''; msg37=trim(mycall14)//' '//trim(hiscall)//' '//trim(rpt(i))
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ if(i.eq.1) itone1=itone
+ idtone56(i,1:29)=itone(8:36)
+ idtone56(i,30:58)=itone(44:72)
+ itone56(i,1:79)=itone(1:79)
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall)//' '//trim(rpt(i))
+ msg(i)=msg37
+ enddo
+ do i=54,56
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall14)//' '//trim(rpt(i))
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtone56(i,1:29)=itone(8:36)
+ idtone56(i,30:58)=itone(44:72)
+ itone56(i,1:79)=itone(1:79)
+ msg37=''; msg37=trim(mycall)//' '//trim(hiscall)//' '//trim(rpt(i))
+ msg(i)=msg37
+ enddo
+ msg37=''; msg37=trim(mycall14)//' '//trim(hiscall)
+ msg(53)=msg37
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtone56(53,1:29)=itone(8:36)
+ idtone56(53,30:58)=itone(44:72)
+ itone56(53,1:79)=itone(1:79)
+ go to 2
+ endif
+
+2 m=13441 ! 7*1920+1
+ call gen_ft8wavevar(itone1,79,1920,2.0,12000.0,0.0,csig0,xjunk,1,151680)
+ do j=0,18
+ do k=1,32; csynce(j,k)=csig0(m); m=m+60; enddo
+ enddo
+
+ return
+end subroutine tone8
diff --git a/lib/ft8var/tone8myc.f90 b/lib/ft8var/tone8myc.f90 new file mode 100755 index 00000000..3efbe748 --- /dev/null +++ b/lib/ft8var/tone8myc.f90 @@ -0,0 +1,14 @@ +subroutine tone8myc()
+
+ use ft8_mod1, only : idtonemyc,mycall
+ character msg37*37,msgsent37*37
+ integer itone(79)
+ integer*1 msgbits(77)
+
+ msg37=''; msg37=trim(mycall)//' AA1AAA FN25'
+ i3=-1; n3=-1
+ call genft8var(msg37,i3,n3,0,msgsent37,msgbits,itone)
+ idtonemyc(1:29)=itone(8:36); idtonemyc(30:58)=itone(44:72)
+
+ return
+end subroutine tone8myc
diff --git a/lib/ft8var/tonesdvar.f90 b/lib/ft8var/tonesdvar.f90 new file mode 100755 index 00000000..8a8dc207 --- /dev/null +++ b/lib/ft8var/tonesdvar.f90 @@ -0,0 +1,81 @@ +subroutine tonesdvar(msgd,lcq)
+
+ use ft8_mod1, only : csyncsd,csyncsdcq,itone76,idtone76,msgsd76
+ complex csig0(151680)
+ character, intent(in) :: msgd*37
+ character msg37*37,msgsent37*37,c1*12,c2*12,grid*6
+ character*4 rpt(75)
+ integer itone(79),itone1(79)
+ integer*1 msgbits(77)
+ logical(1), intent(in) :: lcq
+ logical(1) lgrid,lr73
+
+ data rpt/'+09 ','+08 ','+07 ','+06 ','+05 ','+04 ','+03 ','+02 ','+01 ','+00 ', &
+ '-01 ','-02 ','-03 ','-04 ','-05 ','-06 ','-07 ','-08 ','-09 ','-10 ', &
+ '-11 ','-12 ','-13 ','-14 ','-15 ','-16 ','-17 ','-18 ','-19 ','-20 ', &
+ '-21 ','-22 ','-23 ','-24 ','-25 ','-26 ','R+09','R+08','R+07','R+06', &
+ 'R+05','R+04','R+03','R+02','R+01','R+00','R-01','R-02','R-03','R-04', &
+ 'R-05','R-06','R-07','R-08','R-09','R-10','R-11','R-12','R-13','R-14', &
+ 'R-15','R-16','R-17','R-18','R-19','R-20','R-21','R-22','R-23','R-24', &
+ 'R-25','R-26','RRR ','RR73','73 '/
+
+! taken from ft8_mod1
+! integer itone76(76,79),idtone76(76,58)
+! character*37 msgsd76(76)
+! complex csyncsd(0:18,32),csyncsdcq(0:71,32)
+
+ lgrid=.false.; lr73=.false.
+
+ if(lcq) then
+ msg37=msgd
+ i3=-1; n3=-1
+ call genft8sdvar(msg37,i3,n3,msgsent37,msgbits,itone)
+ else
+ c1=' '; c2=' '
+ ispc1=index(msgd,' '); ispc2=index(msgd((ispc1+1):),' ')+ispc1; ispc3=index(msgd((ispc2+1):),' ')+ispc2;
+ if(len(msgd(1:ispc1-1)).le.12 .and. len(msgd(ispc1+1:ispc2-1)).le.12) then
+ c1=msgd(1:ispc1-1); c2=msgd(ispc1+1:ispc2-1)
+ endif
+ if(index(msgd,' RR73').gt.0 .or. index(msgd,' 73').gt.0) lr73=.true.
+ if(.not.lr73 .and. (ispc3-ispc2).eq.5 .and. msgd(ispc2+1:ispc2+2).ne.'R+' .and. msgd(ispc2+1:ispc2+2).ne.'R-') &
+ lgrid=.true.
+ if(lgrid) then; grid=msgd(ispc2+1:ispc3-1); if(len_trim(grid).ne.4) grid='AA00'
+ else; grid='AA00'
+ endif
+ do i=1,75
+ msg37=' '
+ msg37=trim(c1)//' '//trim(c2)//' '//trim(rpt(i))
+ msgsd76(i)=msg37
+ i3=-1; n3=-1
+ call genft8sdvar(msg37,i3,n3,msgsent37,msgbits,itone)
+ if(i.eq.1) itone1=itone
+ idtone76(i,1:29)=itone(8:36)
+ idtone76(i,30:58)=itone(44:72)
+ itone76(i,1:79)=itone(1:79)
+ enddo
+ msg37=' '
+ msg37=trim(c1)//' '//trim(c2)//' '//trim(grid)
+ msgsd76(76)=msg37
+ i3=-1; n3=-1
+ call genft8sdvar(msg37,i3,n3,msgsent37,msgbits,itone)
+ idtone76(76,1:29)=itone(8:36)
+ idtone76(76,30:58)=itone(44:72)
+ itone76(76,1:79)=itone(1:79)
+ endif
+
+ m=13441 ! 7*1920+1
+ if(lcq) then
+ call gen_ft8wavevar(itone,79,1920,2.0,12000.0,0.0,csig0,xjunk,1,151680)
+ do i=0,57
+ if(i.eq.29) m=m+13440
+ do j=1,32; csyncsdcq(i,j)=csig0(m); m=m+60; enddo
+ enddo
+ else
+ call gen_ft8wavevar(itone1,79,1920,2.0,12000.0,0.0,csig0,xjunk,1,151680)
+ do i=0,18
+ do j=1,32; csyncsd(i,j)=csig0(m); m=m+60; enddo
+ enddo
+ endif
+
+ return
+end subroutine tonesdvar
diff --git a/lib/ft8var/twkfreq1var.f90 b/lib/ft8var/twkfreq1var.f90 new file mode 100755 index 00000000..f4a8be1e --- /dev/null +++ b/lib/ft8var/twkfreq1var.f90 @@ -0,0 +1,26 @@ +subroutine twkfreq1var(ca,nbot,npts,ntop,fsample,a,cb)
+
+ use ft8_mod1, only : twopi
+ complex, intent(in) :: ca(nbot:ntop)
+ complex, intent(out) :: cb(nbot:ntop)
+ complex w,wstep
+ real a(5)
+
+! Mix the complex signal
+ w=1.0; wstep=1.0
+!! x0=0.5*(npts+1)
+!! s=2.0/npts
+ do i=0,npts
+!! x=s*(i-x0) ! valid for 'do i=1,npts'
+!! p2=1.5*x*x - 0.5
+!! p3=2.5*(x**3) - 1.5*x
+!! p4=4.375*(x**4) - 3.75*(x**2) + 0.375
+!! dphi=(a(1) + x*a(2) + p2*a(3) + p3*a(4) + p4*a(5)) * (twopi/fsample)
+ dphi=a(1) * (twopi/fsample)
+ wstep=cmplx(cos(dphi),sin(dphi))
+ w=w*wstep
+ cb(i)=w*ca(i)
+ enddo
+
+ return
+end subroutine twkfreq1var
diff --git a/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff b/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff Binary files differdeleted file mode 100755 index b6f0f2fa..00000000 --- a/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff +++ /dev/null diff --git a/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff b/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff Binary files differdeleted file mode 100755 index ae2cbdd6..00000000 --- a/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff +++ /dev/null diff --git a/lib/gen_cw_wave.f90 b/lib/gen_cw_wave.f90 new file mode 100755 index 00000000..9963b7a3 --- /dev/null +++ b/lib/gen_cw_wave.f90 @@ -0,0 +1,57 @@ +subroutine gen_cw_wave(message,ifreq,wave)
+
+! Generate audio waveform for a short CW message.
+
+ parameter (NMAX=98304) !2.048*48000
+ character*(*) message
+ integer icw(200) !Encoded CW message bits
+ real*4 z(NMAX)
+ real*8 dt,twopi,phi,dphi,fsample,tdit,t
+ real*4 wave(NMAX) !Generated waveform
+ real x(NMAX)
+ real y(NMAX)
+
+ call morse(message,icw,ncw)
+
+ i1=0
+ i2=0
+ do i=1,ncw
+ if(i1.eq.0 .and. icw(i).eq.1) i1=i
+ if(icw(i).eq.1) i2=i+1
+ enddo
+ if(i1.lt.1 .or. i2.gt.200) go to 999
+ ncw=i2-i1+1
+ icw(1:ncw)=icw(i1:i2)
+
+ fsample=48000.d0
+ nspd=2.048d0*fsample/ncw
+ wpm=1.2d0*fsample/nspd
+ dt=1.d0/fsample !Sample interval (s)
+ tdit=nspd*dt
+ twopi=8.d0*atan(1.d0)
+ dphi=twopi*ifreq*dt
+ phi=0.
+ k=0 !Start audio at t=0
+ t=0.
+ x=0.
+ do i=1,NMAX
+ t=t+dt
+ j=t/tdit + 1
+ phi=phi + dphi
+ if(phi.gt.twopi) phi=phi-twopi
+ xphi=phi
+ k=k+1
+ x(k)=icw(j)
+ z(k)=sin(xphi)
+ enddo
+
+ nadd=0.002/dt
+ call smo(x,NMAX,y,nadd)
+ call smo(y,NMAX,x,nadd)
+ call smo(x,NMAX,y,nadd)
+ y(NMAX-3*NADD:NMAX)=0.
+ fac=0.99999/maxval(abs(y))
+ wave=fac*y*z
+
+999 return
+end subroutine gen_cw_wave
diff --git a/lib/gen_echocall.f90 b/lib/gen_echocall.f90 new file mode 100755 index 00000000..7741d149 --- /dev/null +++ b/lib/gen_echocall.f90 @@ -0,0 +1,15 @@ +subroutine gen_EchoCall(callsign,itone)
+
+ character*6 callsign
+ integer itone(6)
+
+ itone=0 !Default character is blank
+ do i=1,len(trim(callsign))
+ m=ichar(callsign(i:i))
+ if(m.ge.48 .and. m.le.57) itone(i)=m-47 !0-9
+ if(m.ge.65 .and. m.le.90) itone(i)=m-54 !A-Z
+ if(m.ge.97 .and. m.le.122) itone(i)=m-86 !a-z
+ enddo
+
+ return
+end subroutine gen_EchoCall
diff --git a/lib/genwave.f90 b/lib/genwave.f90 index 8cd47269..4d9b55cb 100755 --- a/lib/genwave.f90 +++ b/lib/genwave.f90 @@ -1,15 +1,14 @@ -subroutine genwave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave)
+subroutine genwave(itone,nsym,nsps,nwave,fsample,tonespacing,f0,icmplx, &
+ cwave,wave)
+ real*8 tonespacing
real wave(nwave)
complex cwave(nwave)
- integer hmod
integer itone(nsym)
- logical ex
- real*8 dt,phi,dphi,twopi,freq,baud
+ real*8 dt,phi,dphi,twopi,freq
dt=1.d0/fsample
twopi=8.d0*atan(1.d0)
- baud=fsample/nsps
! Calculate the audio waveform
phi=0.d0
@@ -17,7 +16,7 @@ subroutine genwave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave) if(icmplx.eq.1) cwave=0.
k=0
do j=1,nsym
- freq=f0 + itone(j)*hmod*baud
+ freq=f0 + itone(j)*tonespacing
dphi=twopi*freq*dt
do i=1,nsps
k=k+1
@@ -31,22 +30,5 @@ subroutine genwave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave) enddo
enddo
-!### TEMPORARY code to allow transmitting both A and B submodes
- inquire(file='Q65_Tx2',exist=ex)
- if(ex) then
- k=0
- do j=1,nsym
- freq=f0 + itone(j)*2.d0*hmod*baud + 500.d0
- dphi=twopi*freq*dt
- do i=1,nsps
- k=k+1
- wave(k)=0.5*(wave(k)+sin(phi))
- phi=phi+dphi
- if(phi.gt.twopi) phi=phi-twopi
- enddo
- enddo
- endif
-!###
-
return
end subroutine genwave
diff --git a/lib/get_q3list.f90 b/lib/get_q3list.f90 new file mode 100755 index 00000000..54199148 --- /dev/null +++ b/lib/get_q3list.f90 @@ -0,0 +1,132 @@ +subroutine get_q3list(fname,bDiskData,nlist,list)
+
+ type q3list
+ character*6 call
+ character*4 grid
+ integer nsec
+ integer nfreq
+ integer moonel
+ end type q3list
+
+ parameter (MAX_CALLERS=40)
+ character*(*) fname
+ character*36 list(40)
+ character*8 grid6
+ logical*1 bDiskData
+ integer time
+ integer nt(8)
+ integer indx(MAX_CALLERS)
+ type(q3list) ctmp(MAX_CALLERS),callers(MAX_CALLERS)
+ character*256 jpleph_file_name,file24name
+ common/jplcom/jpleph_file_name
+ common/lu24com/file24name
+
+ nhist2=0
+ open(24,file=fname,status='unknown',form='unformatted')
+ read(24,end=1) nhist2
+ if(nhist2.ge.1 .and. nhist2.le.40) then
+ read(24,end=1) ctmp(1:nhist2)
+ else
+ nhist2=0
+ endif
+1 rewind 24
+ if(nhist2.eq.0) go to 900
+
+ now=time()
+ call date_and_time(values=nt)
+ uth=nt(5) + (nt(6)-nt(4))/60.0 + nt(7)/3600.0
+ j=0
+
+ do i=1,nhist2
+ age=(now - ctmp(i)%nsec)/3600.0
+ if(age.gt.24.0) cycle
+ grid6=ctmp(i)%grid//'mm'
+ call grid2deg(grid6,xlon,xlat)
+ call sun(nt(1),nt(2),nt(3),uth,-xlon,xlat,RASun,DecSun,xLST, &
+ AzSun,ElSun,mjd,day)
+ call moondopjpl(nt(1),nt(2),nt(3),uth,-xlon,xlat,RAMoon,DecMoon, &
+ xLST,HA,AzMoon,ElMoon,vr,techo)
+ if(ElMoon.lt.-5.0 .and. (.not.bDiskData)) cycle
+ j=j+1 !Keep this one...
+ callers(j)=ctmp(i)
+ callers(j)%moonel=nint(ElMoon) !... and save its current moonel
+ enddo
+
+ nhist2=j
+ write(24) nhist2
+ write(24) callers(1:nhist2)
+
+ call indexx(callers(1:nhist2)%nfreq,nhist2,indx)
+ do i=1,nhist2
+ j=indx(i)
+ moon_el=nint(ElMoon)
+ age=(now - callers(j)%nsec)/3600.0
+ write(list(i),1000) i,callers(j)%nfreq,callers(j)%call, &
+ callers(j)%grid,callers(j)%moonel,age,char(0)
+1000 format(i2,'.',i6,2x,a6,2x,a4,i5,f7.1,a1)
+
+! h1=mod(now,86400)/3600.0
+! h2=mod(callers(i)%nsec,86400)/3600.0
+! hd=h1-h2
+! if(hd.lt.0.0) hd=hd+24.0
+! write(*,3301) i,callers(i)%call,now,callers(i)%nsec,h1,h2,hd
+!3301 format(i3,2x,a6,2i12,3f10.6)
+
+ enddo
+
+900 close(24)
+ nlist=nhist2
+ file24name=fname
+
+ return
+end subroutine get_q3list
+
+subroutine rm_q3list(dxcall0)
+
+ parameter (MAX_CALLERS=40)
+ type q3list
+ character*6 call
+ character*4 grid
+ integer nsec
+ integer nfreq
+ integer moonel
+ end type q3list
+ character*(*) dxcall0
+ character*6 dxcall
+ character*256 file24name
+ type(q3list) callers(MAX_CALLERS)
+ common/lu24com/file24name
+
+ dxcall=dxcall0
+ open(24,file=trim(file24name),status='unknown',form='unformatted')
+ read(24) nhist2
+ read(24) callers(1:nhist2)
+
+ if(nhist2.eq.MAX_CALLERS .and. dxcall.eq.callers(nhist2)%call) then
+ nhist2=MAX_CALLERS - 1
+ go to 10
+ endif
+
+ iz=nhist2
+ do i=1,iz
+ if(callers(i)%call .eq. dxcall) then
+ nhist2=nhist2-1
+ callers(i:nhist2)=callers(i+1:nhist2+1) !Remove dxcall from q3list
+ exit
+ endif
+ enddo
+
+10 rewind 24
+ write(24) nhist2
+ write(24) callers(1:nhist2)
+ close(24)
+
+ return
+end subroutine rm_q3list
+
+subroutine jpl_setup(fname)
+ character*256 fname,jpleph_file_name
+ common/jplcom/jpleph_file_name
+ jpleph_file_name=fname
+ return
+end subroutine jpl_setup
diff --git a/lib/go_chkfft.cmd b/lib/go_chkfft.cmd index 375a194e..f07411d6 100755 --- a/lib/go_chkfft.cmd +++ b/lib/go_chkfft.cmd @@ -1 +1 @@ -gfortran -o chkfft chkfft3.f90 four2a.f90 gran.c /jtsdk/fftw3f/libfftw3f-3.dll
+gfortran -o chkfft3 chkfft3.f90 four2a.f90 gran.c libfftw3f-3.dll
diff --git a/lib/hspec.f90 b/lib/hspec.f90 index b86163f4..6dd8539a 100755 --- a/lib/hspec.f90 +++ b/lib/hspec.f90 @@ -19,9 +19,10 @@ subroutine hspec(id2,k,nutc0,ntrpdepth,nrxfreq,ntol,bmsk144, & ! jh index of most recent data in green(), s()
parameter (JZ=703)
- character*80 line1
+ character*(*) line1
+ character*80 line0
character*(*) datadir
- character*12 mycall,hiscall
+ character*(*) mycall,hiscall
integer*2 id2(0:120*12000-1)
logical*1 bmsk144,bshmsg,btrain,bswl
real green(0:JZ-1)
@@ -96,7 +97,12 @@ subroutine hspec(id2,k,nutc0,ntrpdepth,nrxfreq,ntol,bmsk144, & tt2=sum(float(abs(id2(k0:k0+3583))))
if(tt1.ne.0.0 .and. tt2.ne.0) then
call mskrtd(id2(k-7168+1:k),nutc0,tsec,ntol,nrxfreq,ndepth, &
- mycall,hiscall,bshmsg,btrain,pcoeffs,bswl,datadir,line1)
+ mycall,hiscall,bshmsg,btrain,pcoeffs,bswl,datadir,line0)
+ if(line0(1:1).eq.char(0)) then
+ line1(1:1)=char(0)
+ else
+ line1(1:62)=line0(1:62)
+ endif
endif
endif
endif
diff --git a/lib/jt4_decode.f90 b/lib/jt4_decode.f90 index ccbf6927..948550da 100755 --- a/lib/jt4_decode.f90 +++ b/lib/jt4_decode.f90 @@ -130,7 +130,7 @@ contains ! syncmin=3.0 + minsync
syncmin=1.0+minsync
naggressive=0
- if(ndepth.ge.2) naggressive=1
+ if(iand(ndepth,7).ge.2) naggressive=1
nq1=3
nq2=6
if(naggressive.eq.1) nq1=1
@@ -178,6 +178,7 @@ contains qabest=0.
prtavg=.false.
+ idf=0
do idt=-2,2
dtx=dtxz + 0.03*idt
nfreq=nfreqz + 2*idf
@@ -189,12 +190,12 @@ contains call timer('decode4 ',1)
if(nfano.gt.0) then
+ call getsnr(dat,npts,mode4,dtx,decoded,nsnr)
! Fano succeeded: report the message and return !Fano OK
if (associated (this%decode_callback)) then
call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, &
.false.,decoded,99.,ich,.false.,0)
end if
-!### nsave=0
go to 990
else !Fano failed
@@ -252,6 +253,7 @@ contains qual=qbest
if (associated (this%decode_callback)) then
+ if(qual.gt.0.0) call getsnr(dat,npts,mode4,dtx,deepmsg,nsnr)
if(int(qual).ge.nq1) then
call this%decode_callback(nsnr,dtx,nfreqz,.true.,csync,.true., &
deepmsg,qual,ich,.false.,0)
@@ -410,3 +412,73 @@ contains 900 return
end subroutine avg4
end module jt4_decode
+
+subroutine getsnr(dat,npts,mode4,dtx,decoded,nsnr)
+
+! Compute SNR using raw data, T, DF, and decoded message.
+
+ parameter(NSPS=1260,NH=NSPS/2)
+ real dat(npts)
+ real x(NSPS)
+ real s(NH),savg(NH)
+ complex cx(0:NSPS/2)
+ integer itone(206)
+ integer ipk(1)
+ character*22 decoded,msgsent
+ equivalence (x,cx)
+
+ call gen4(decoded,0,msgsent,itone,itype) !Get itone values for this message
+ dt=1.0/5512.5
+ df=5512.5/NSPS
+ istart=(dtx+1.08)/dt
+
+ savg=0.
+ do j=1,206 !Loop over all symbols
+ cx=0.
+ do i=1,NSPS
+ k=(j-1)*NSPS + i + istart
+ if(k.ge.1 .and. k.le.npts) x(i)=dat(k)
+ enddo
+ call four2a(cx,NSPS,1,-1,0) !r2c FFT
+ do i=1,nh
+ s(i)=real(cx(i))**2 + aimag(cx(i))**2
+ enddo
+ jtone=nint((fpk-1500)/(mode4*df))
+ nshift=mode4*itone(j)
+ savg=savg + cshift(s,nshift) !Move all power into lowest tone freq
+ enddo
+
+ nskip=mode4/2
+ call averms(savg,nh,nskip,ave,rms)
+ savg=(savg-ave)/rms
+
+ do i=1,mode4/4
+ call smo121(savg,nh)
+ enddo
+
+ ipk=maxloc(savg)
+ psig=0.
+ do i=ipk(1),1,-1
+ if(savg(i).lt.0) exit
+ psig=psig + savg(i)
+ enddo
+ i1=i+1
+ do i=ipk(1),nh
+ if(savg(i).lt.0) exit
+ psig=psig + savg(i)
+ enddo
+ i2=i-1
+ pnoise=2500.0*sqrt(206.0)/df
+ snrdb=db(psig/pnoise)
+ nsnr=nint(snrdb)
+ width=(i2-i1)*df
+
+! rewind(62)
+! do i=1,nh
+! write(62,1010) i*df,savg(i)
+!1010 format(2f10.3)
+! enddo
+! flush(62)
+
+ return
+end subroutine getsnr
diff --git a/lib/jt65_mod6.f90 b/lib/jt65_mod6.f90 new file mode 100755 index 00000000..016286dd --- /dev/null +++ b/lib/jt65_mod6.f90 @@ -0,0 +1,11 @@ +! This source code file was last time modified by Igor UA3DJY on January 23rd, 2018
+! All changes are shown in the patch file coming together with the full JTDX source code.
+
+module jt65_mod6
+
+ integer, parameter :: NPTS=624000
+ real*4 dd(NPTS)
+ integer nnmode
+ save
+
+end module jt65_mod6
\ No newline at end of file diff --git a/lib/jt9.f90 b/lib/jt9.f90 index fbe57c1c..ee2c0191 100755 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -10,6 +10,8 @@ program jt9 use timer_module, only: timer
use timer_impl, only: init_timer, fini_timer
use readwav
+ use ft8_mod1, only : dd8
+ use jt65_mod6, only : dd
include 'jt9com.f90'
@@ -21,13 +23,15 @@ program jt9 character c
character(len=500) optarg, infile
character wisfile*256
-!### ndepth was defined as 60001. Why???
+
integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, &
- fhigh=4000,nrxfreq=1500,ndepth=1,nexp_decode=0,nQSOProg=0
+ fhigh=4000,nrxfreq=1500,ndepth=1,nexp_decode=0,nQSOProg=0,ncycles=3, &
+ nft8rxfsens=3,nmt=0,nmtft8decsens=3,ndecoderstart=3
logical :: read_files = .true., tx9 = .false., display_help = .false., &
bLowSidelobes = .false., nexp_decode_set = .false., &
- have_ntol = .false.
- type (option) :: long_options(31) = [ &
+ have_ntol = .false.,multift8 = .false.,hidedupes = .false., &
+ lft8lowth = .true.,lft8subpass = .true.,lwidedxcsearch = .true.
+ type (option) :: long_options(41) = [ &
option ('help', .false., 'h', 'Display this help message', ''), &
option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), &
option ('tr-period', .true., 'p', 'Tx/Rx period, default SECONDS=60', &
@@ -42,7 +46,7 @@ program jt9 option ('lowest', .true., 'L', &
'Lowest frequency decoded (JT65), default HERTZ=200', 'HERTZ'), &
option ('highest', .true., 'H', &
- 'Highest frequency decoded, default HERTZ=4007', 'HERTZ'), &
+ 'Highest frequency decoded, default HERTZ=4000', 'HERTZ'), &
option ('split', .true., 'S', &
'Lowest JT9 frequency decoded, default HERTZ=2700', 'HERTZ'), &
option ('rx-frequency', .true., 'f', &
@@ -54,15 +58,38 @@ program jt9 option ('fft-threads', .true., 'm', &
'Number of threads to process large FFTs, default THREADS=1', &
'THREADS'), &
+ option ('multithreadft8', .false., 'M', 'Use Multithread FT8 Decoder', &
+ ''), &
+ option ('MTft8-cycles', .true., 'C', &
+ 'Number of cycles for MTft8 decoder (1-3), default CYCLES=3', &
+ 'CYCLES'), &
+ option ('MTft8-hidedupes', .false., 'U', 'Hide MTft8 Dupes', &
+ ''), &
+ option ('MTft8-RxFreqSens', .true., 'R', &
+ 'RxFreqSensitivity for MTft8 decoder (1-3), default RXFREQSENS=3', &
+ 'RXFREQSENS'), &
+ option ('MTft8-NumThreads', .true., 'N', &
+ 'Number of threads for MTft8 decoder (0-12), default NUMTHREADS=0', &
+ 'NUMTHREADS'), &
+ option ('MTft8-DecSens', .true., 'E', &
+ 'MTft8 decoder sensitivity (1-3), default SENSITIVITY=3', &
+ 'SENSITIVITY'), &
+ option ('MTft8-StartTime', .true., 'D', &
+ 'MTft8 decoder start (0-4), default START_TIME=3 (Normal)', &
+ 'START_TIME'), &
+ option ('Skip-MTft8-WideDxCallSearch', .false., 'Z', &
+ 'SKIP MTft8 Wideband DX Call Search', ''), &
option ('q65', .false., '3', 'Q65 mode', ''), &
option ('jt4', .false., '4', 'JT4 mode', ''), &
option ('ft4', .false., '5', 'FT4 mode', ''), &
option ('jt65', .false.,'6', 'JT65 mode', ''), &
option ('fst4', .false., '7', 'FST4 mode', ''), &
option ('fst4w', .false., 'W', 'FST4W mode', ''), &
+ option ('fst4w', .false., 'Y', 'FST4W mode, print hash22 values', ''), &
option ('ft8', .false., '8', 'FT8 mode', ''), &
option ('jt9', .false., '9', 'JT9 mode', ''), &
- option ('qra64', .false., 'q', 'QRA64 mode', ''), &
+ option ('quiet', .false., 'q', 'Quiet mode, no <DecodeFinished>', ''), &
+ option ('msk144', .false., 'k', 'MSK144 mode', ''), &
option ('QSOprog', .true., 'Q', 'QSO progress (0-5), default PROGRESS=1',&
'QSOprogress'), &
option ('sub-mode', .true., 'b', 'Sub mode, default SUBMODE=A', 'A'), &
@@ -85,13 +112,12 @@ program jt9 common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano
data npatience/1/,nthreads/1/,wisfile/' '/
- iwspr=0
nsubmode = 0
ntol = 20
TRperiod=60.d0
do
- call getopt('hs:e:a:b:r:m:p:d:f:F:w:t:9876543WqTL:S:H:c:G:x:g:X:Q:', &
+ call getopt('hs:e:a:b:r:m:p:d:f:F:w:t:9876543WYqkTMUSZL:S:H:c:G:x:g:X:Q:C:R:N:E:D:', &
long_options,c,optarg,arglen,stat,offset,remain,.true.)
if (stat .ne. 0) then
exit
@@ -127,8 +153,26 @@ program jt9 read (optarg(:arglen), *) fsplit
case ('H')
read (optarg(:arglen), *) fhigh
+ case ('M')
+ multift8 = .true.
+ case ('C')
+ read (optarg(:arglen), *) ncycles
+ case ('U')
+ hidedupes = .true.
+ case ('R')
+ read (optarg(:arglen), *) nft8rxfsens
+ case ('N')
+ read (optarg(:arglen), *) nmt
+ case ('E')
+ read (optarg(:arglen), *) nmtft8decsens
+ case ('D')
+ read (optarg(:arglen), *) ndecoderstart
+ case ('Z')
+ lwidedxcsearch = .false.
case ('q')
- mode = 164
+ lquiet=.true.
+ case ('k')
+ mode = 144
case ('Q')
read (optarg(:arglen), *) nQSOProg
case ('3')
@@ -141,7 +185,6 @@ program jt9 if (mode.lt.65) mode = mode + 65
case ('7')
mode = 240
- iwspr=0
case ('8')
mode = 8
case ('9')
@@ -152,7 +195,8 @@ program jt9 read (optarg(:arglen), *) npatience
case ('W')
mode = 241
- iwspr=1
+ case ('Y')
+ mode = 242
case ('c')
read (optarg(:arglen), *) mycall
case ('G')
@@ -212,7 +256,7 @@ program jt9 hisgrid=' '
endif
- if (mode .eq. 241) then
+ if (mode .eq. 241 .or. mode .eq. 242) then
ntol = min (ntol, 100)
else if (mode .eq. 65 + 9 .and. .not. have_ntol) then
ntol = 20
@@ -221,11 +265,13 @@ program jt9 else
ntol = min (ntol, 1000)
end if
+
if (.not. nexp_decode_set) then
- if (mode .eq. 240 .or. mode .eq. 241) then
+ if (mode .eq. 240 .or. mode .eq. 241 .or. mode .eq. 242) then
nexp_decode = 3 * 256 ! single decode off and nb=0
end if
end if
+
allocate(shared_data)
nflatten=0
do iarg = offset + 1, offset + remain
@@ -277,10 +323,12 @@ program jt9 call timer('symspec ',1)
endif
nhsym0=nhsym
- if(nhsym.ge.181 .and. mode.ne.240 .and. mode.ne.241 .and. mode.ne.66) exit
+ if(nhsym.ge.181 .and. mode.ne.240 .and. mode.ne.241 .and. &
+ mode.ne.242 .and. mode.ne.66) exit
endif
enddo
close(unit=wav%lun)
+
shared_data%params%nutc=nutc
shared_data%params%ndiskdat=.true.
shared_data%params%ntr=TRperiod
@@ -294,7 +342,6 @@ program jt9 shared_data%params%kin=64800
if(mode.eq.240) shared_data%params%kin=720000 !### 60 s periods ###
shared_data%params%nzhsym=nhsym
- if(mode.eq.240 .and. iwspr.eq.1) ndepth=ior(ndepth,128)
shared_data%params%ndepth=ndepth
shared_data%params%lft8apon=.true.
shared_data%params%ljt65apon=.true.
@@ -310,6 +357,7 @@ program jt9 shared_data%params%nranera=6 !### ntrials=3000
shared_data%params%nrobust=.false.
shared_data%params%nexp_decode=nexp_decode
+ shared_data%params%lmultift8=multift8
shared_data%params%mycall=transfer(mycall,shared_data%params%mycall)
shared_data%params%mygrid=transfer(mygrid,shared_data%params%mygrid)
shared_data%params%hiscall=transfer(hiscall,shared_data%params%hiscall)
@@ -326,13 +374,50 @@ program jt9 end if
shared_data%params%nsubmode=nsubmode
+ if (multift8 .and. mode.eq.8) then
+ shared_data%params%lft8subpass = .true.
+ shared_data%params%lhideft8dupes = hidedupes
+ shared_data%params%nft8cycles = ncycles
+ shared_data%params%nmt = nmt
+ if(nmtft8decsens.eq.1) then
+ lft8lowth = .false.
+ lft8subpass = .false.
+ elseif(nmtft8decsens.eq.2) then
+ lft8lowth = .true.
+ lft8subpass = .false.
+ elseif(nmtft8decsens.eq.3) then
+ lft8lowth = .true.
+ lft8subpass = .true.
+ end if
+ shared_data%params%lft8lowth = lft8lowth
+ shared_data%params%lft8subpass = lft8subpass
+ shared_data%params%ndecoderstart = ndecoderstart
+ shared_data%params%lwidedxcsearch = lwidedxcsearch
+ shared_data%params%ndtcenter = 0
+ shared_data%params%lmodechanged = .false.
+ shared_data%params%nsecbandchanged = 0
+ shared_data%params%ncandthin = 100
+ shared_data%params%nft8rxfsens = nft8rxfsens
+ shared_data%params%lhound = .false.
+ shared_data%params%lcommonft8b = .true.
+ shared_data%params%lbandchanged = .false.
+ shared_data%params%lmultinst = .false.
+ shared_data%params%nlasttx = 0
+ shared_data%params%nhint = .false.
+ shared_data%params%ndelay = 0
+ shared_data%params%nprepass = 4
+ shared_data%params%nharmonicsdepth = 0
+ shared_data%params%nsdecatt = 1
+ !print*,'lwidedxcsearch ',shared_data%params%lwidedxcsearch
+ end if
!### temporary, for MAP65:
if(mode.eq.66 .and. TRperiod.eq.60) shared_data%params%emedelay=2.5
datetime="2013-Apr-16 15:13" !### Temp
shared_data%params%datetime=transfer(datetime,shared_data%params%datetime)
if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit
- if(mode.eq.8) then
+ nearly=50
+ if(mode.eq.8 .and. .not. shared_data%params%lmultift8) then
! "Early" decoding pass, FT8 only, when jt9 reads data from disk
nearly=41
shared_data%params%nzhsym=nearly
@@ -352,7 +437,52 @@ program jt9 call multimode_decoder(shared_data%ss,id2a, &
shared_data%params,nfsample)
cycle
+ else if(mode.eq.8 .and. shared_data%params%lmultift8) then
+ if(shared_data%params%ndecoderstart.lt.2) then
+ nearly=41
+ shared_data%params%lmultift8=.false.
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ call multimode_decoder(shared_data%ss,id2a, &
+ shared_data%params,nfsample)
+ if(shared_data%params%ndecoderstart.lt.2) then
+ nearly=46
+ shared_data%params%lmultift8=.false.
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ call multimode_decoder(shared_data%ss,id2a, &
+ shared_data%params,nfsample)
+ endif
+ if(shared_data%params%ndecoderstart.eq.0) nearly=49
+ if(shared_data%params%ndecoderstart.eq.1) nearly=50
+ shared_data%params%lmultift8=.true.
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ dd(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd(nearly*3456+1:)=0
+ dd8(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd8(nearly*3456+1:)=0
+ else
+ if(shared_data%params%ndecoderstart.eq.2) nearly=48
+ if(shared_data%params%ndecoderstart.eq.3) nearly=49
+ if(shared_data%params%ndecoderstart.eq.4) nearly=50
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ dd(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd(nearly*3456+1:)=0
+ dd8(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd8(nearly*3456+1:)=0
+ endif
+
+ ! MSK144
+ else if (mode .eq. 144) then
+ call decode_msk144(shared_data%id2, shared_data%params, data_dir)
endif
+
! Normal decoding pass
call multimode_decoder(shared_data%ss,shared_data%id2, &
shared_data%params,nfsample)
@@ -362,12 +492,20 @@ program jt9 call timer('jt9 ',101)
999 continue
+
! Output decoder statistics
call fini_timer ()
+
! Save FFTW wisdom and free memory
if(len(trim(wisfile)).gt.0) iret=fftwf_export_wisdom_to_filename(wisfile)
- call four2a(a,-1,1,1,1)
- call filbig(a,-1,1,0.0,0,0,0,0,0) !used for FFT plans
+ if(mode.eq.8 .and. shared_data%params%lmultift8) then
+ call four2avar(a,-1,1,1,1)
+ call filbigvar(-1.,0,0.,0,0.,0.,0) !used for FFT plans for FT8 multithread detector
+ else
+ call four2a(a,-1,1,1,1)
+ call filbig(a,-1,1,0.0,0,0,0,0,0) !used for all other FFT plans
+ endif
call fftwf_cleanup_threads()
call fftwf_cleanup()
+
end program jt9
diff --git a/lib/jt9a.f90 b/lib/jt9a.f90 index 46140fc5..8e94062d 100755 --- a/lib/jt9a.f90 +++ b/lib/jt9a.f90 @@ -4,6 +4,8 @@ subroutine jt9a() use timer_module, only: timer
use timer_impl, only: init_timer !, limtrace
use shmem
+ use ft8_mod1, only : dd8
+ use jt65_mod6, only : dd
include 'jt9com.f90'
@@ -22,7 +24,7 @@ subroutine jt9a() call shmem_setkey(trim(shm_key)//c_null_char)
ok=shmem_attach()
if(.not.ok) call abort
- msdelay=30
+ msdelay=10
call c_f_pointer(shmem_address(),shared_data)
! Terminate if ipc(2) is 999
@@ -32,8 +34,7 @@ subroutine jt9a() ok=shmem_unlock()
ok=shmem_detach()
go to 999
- endif
-! Wait here until GUI has set ipc(2) to 1
+ endif! Wait here until GUI has set ipc(2) to 1
if(shared_data%ipc(2).ne.1) then
ok=shmem_unlock()
if(.not.ok) call abort
@@ -41,7 +42,6 @@ subroutine jt9a() go to 10
endif
shared_data%ipc(2)=0
-
nbytes=shmem_size()
if(nbytes.le.0) then
ok=shmem_unlock()
@@ -56,7 +56,7 @@ subroutine jt9a() call flush(6)
call timer('decoder ',0)
if(local_params%nmode.eq.8 .and. local_params%ndiskdat .and. &
- .not. local_params%nagain) then
+ .not. local_params%nagain .and. .not. local_params%lmultift8) then
! Early decoding pass, FT8 only, when wsjtx reads from disk
nearly=41
local_params%nzhsym=nearly
@@ -70,11 +70,85 @@ subroutine jt9a() call multimode_decoder(shared_data%ss,id2a,local_params,12000)
local_params%nzhsym=50
endif
-! Normal decoding pass
- call multimode_decoder(shared_data%ss,shared_data%id2,local_params,12000)
- call timer('decoder ',1)
+
+ !ft8md
+ if(local_params%nmode.eq.8 .and. local_params%lmultift8 .and. &
+ .not. local_params%nagain .and. local_params%ndiskdat) then
+ npts1=180000
+ if(local_params%ndecoderstart.lt.2) then
+ nearly=41
+ local_params%lmultift8=.false.
+ local_params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ call multimode_decoder(shared_data%ss,id2a,local_params,12000)
+ if(local_params%ndecoderstart.lt.2) then
+ nearly=46
+ local_params%lmultift8=.false.
+ local_params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ call multimode_decoder(shared_data%ss,id2a,local_params,12000)
+ endif
+ if(local_params%ndecoderstart.eq.0) nearly=49
+ if(local_params%ndecoderstart.eq.1) nearly=50
+ local_params%lmultift8=.true.
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ dd(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd(nearly*3456+1:)=0
+ dd8(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd8(nearly*3456+1:)=0
+ if(local_params%ndecoderstart.eq.0) shared_data%params%nzhsym=49
+ if(local_params%ndecoderstart.eq.1) shared_data%params%nzhsym=50
+ else
+ nearly=50
+ if(local_params%ndecoderstart.eq.2) nearly=48
+ if(local_params%ndecoderstart.eq.3) nearly=49
+ if(local_params%ndecoderstart.eq.4) nearly=50
+ shared_data%params%nzhsym=nearly
+ id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ id2a(nearly*3456+1:)=0
+ dd(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd(nearly*3456+1:)=0
+ dd8(1:nearly*3456)=shared_data%id2(1:nearly*3456)
+ dd8(nearly*3456+1:)=0
+ if(local_params%ndecoderstart.eq.2) shared_data%params%nzhsym=48
+ if(local_params%ndecoderstart.eq.3) shared_data%params%nzhsym=49
+ if(local_params%ndecoderstart.eq.4) shared_data%params%nzhsym=50
+ endif
+ elseif (local_params%nmode.eq.8 .and. local_params%lmultift8 .and. .not. &
+ local_params%ndiskdat) then
+ dd(1:npts1)=shared_data%id2(1:npts1)
+ rms=sum(abs(dd(1:10))) + sum(abs(dd(76001:76010))) + sum(abs(dd(151670:151680)))
+ dd8(1:npts1)=dd(1:npts1)
+!### WHY WAS THIS STUFF HERE ??? ###
+! if(rms.gt.0.001) then
+! dd(1:npts1)=shared_data%dd2(1:npts1)
+! dd8(1:npts1)=dd(1:npts1)
+!print *,'win7',rms
+! else ! workaround for zero data values of dd2 array under WinXP
+! dd(1:npts1)=shared_data%id2(1:npts1)
+! dd8(1:npts1)=dd(1:npts1)
+!print *, 'winxp',rms
+! endif
+!###
+ endif
+ !end ft8md
+
+ if(local_params%nmode .eq. 144) then
+ ! MSK144
+ call decode_msk144(shared_data%id2, shared_data%params, data_dir)
+ else
+ ! Normal decoding pass
+ call multimode_decoder(shared_data%ss,shared_data%id2,local_params,12000)
+ endif
+
+ call timer('decoder ',1)
+!print*,time, ' jt9a before final loop which waits for ipc(3) ==1' !ft8md
! Wait here until GUI routine decodeDone() has set ipc(3) to 1
100 ok=shmem_lock()
if(.not.ok) call abort
diff --git a/lib/jt9com.f90 b/lib/jt9com.f90 index 97b3ab27..ed71010c 100755 --- a/lib/jt9com.f90 +++ b/lib/jt9com.f90 @@ -1,5 +1,4 @@ use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char, c_bool
-
include 'constants.f90'
!
@@ -47,6 +46,49 @@ character(kind=c_char) :: mygrid(6)
character(kind=c_char) :: hiscall(12)
character(kind=c_char) :: hisgrid(6)
+ logical(c_bool) :: b_even_seq
+ logical(c_bool) :: b_superfox
+ integer(c_int) :: yymmdd
+
+ ! below is ft8md
+ character(kind=c_char) :: mybcall(12)
+ character(kind=c_char) :: hisbcall(12)
+ integer(c_int) :: ncandthin
+ integer(c_int) :: ndtcenter
+ integer(c_int) :: nft8cycles
+ integer(c_int) :: ntrials10
+ integer(c_int) :: ntrialsrxf10
+ integer(c_int) :: nharmonicsdepth
+ integer(c_int) :: ntopfreq65
+ integer(c_int) :: nprepass
+ integer(c_int) :: nsdecatt
+ integer(c_int) :: nlasttx
+ integer(c_int) :: ndelay
+ integer(c_int) :: nmt
+ integer(c_int) :: nft8rxfsens
+ integer(c_int) :: nft4depth
+ integer(c_int) :: nsecbandchanged
+ logical(c_bool) :: nagainfil
+ logical(c_bool) :: nstophint
+ logical(c_bool) :: nhint
+ logical(c_bool) :: fmaskact
+ logical(c_bool) :: lmultift8
+ logical(c_bool) :: lft8lowth
+ logical(c_bool) :: lft8subpass
+ logical(c_bool) :: ltxing
+ logical(c_bool) :: lhideft8dupes
+ logical(c_bool) :: lhound
+ logical(c_bool) :: lcommonft8b
+ logical(c_bool) :: lmycallstd
+ logical(c_bool) :: lhiscallstd
+ logical(c_bool) :: lapmyc
+ logical(c_bool) :: lmodechanged
+ logical(c_bool) :: lbandchanged
+ logical(c_bool) :: lenabledxcsearch
+ logical(c_bool) :: lwidedxcsearch
+ logical(c_bool) :: lmultinst
+ logical(c_bool) :: lskiptx1
+ integer(c_int) :: ndecoderstart
end type params_block
type, bind(C) :: dec_data
diff --git a/lib/map65_mmdec.f90 b/lib/map65_mmdec.f90 index 2b642f96..7d592d33 100755 --- a/lib/map65_mmdec.f90 +++ b/lib/map65_mmdec.f90 @@ -1,5 +1,5 @@ -subroutine map65_mmdec(nutc,id2,nqd,nsubmode,nfa,nfb,nfqso,ntol,newdat, &
- nagain,max_drift,mycall,hiscall,hisgrid)
+subroutine map65_mmdec(nutc,id2,nqd,ntrperiod, nsubmode,nfa,nfb,nfqso, &
+ ntol,newdat,nagain,max_drift,ndepth,mycall,hiscall,hisgrid)
use prog_args
use timer_module, only: timer
@@ -14,8 +14,8 @@ subroutine map65_mmdec(nutc,id2,nqd,nsubmode,nfa,nfb,nfqso,ntol,newdat, & logical single_decode,bVHF,lnewdat,lagain,lclearave,lapcqonly
integer*2 id2(300*12000)
+ integer nqf(20)
! type(params_block) :: params
- character(len=20) :: datetime
character(len=12) :: mycall, hiscall
character(len=6) :: hisgrid
data ntr0/-1/
@@ -28,8 +28,7 @@ subroutine map65_mmdec(nutc,id2,nqd,nsubmode,nfa,nfb,nfqso,ntol,newdat, & ! hiscall=transfer(params%hiscall,hiscall)
! mygrid=transfer(params%mygrid,mygrid)
! hisgrid=transfer(params%hisgrid,hisgrid)
- datetime=' '
-
+
my_q65%decoded = 0
ncontest=0
nQSOprogress=0
@@ -40,16 +39,12 @@ subroutine map65_mmdec(nutc,id2,nqd,nsubmode,nfa,nfb,nfqso,ntol,newdat, & lagain=(nagain.ne.0)
bVHF=.true.
emedelay=2.5
- ndepth=1
- ntrperiod=60
-
- open(17,file=trim(temp_dir)//'/red.dat',status='unknown')
- open(14,file=trim(temp_dir)//'/avemsg.txt',status='unknown')
+! ntrperiod=60
call timer('dec_q65 ',0)
call my_q65%decode(q65_decoded,id2,nqd,nutc,ntrperiod,nsubmode,nfqso, &
ntol,ndepth,nfa,nfb,lclearave,single_decode,lagain,max_drift,lnewdat, &
- emedelay,mycall,hiscall,hisgrid,nQSOProgress,ncontest,lapcqonly,navg0)
+ emedelay,mycall,hiscall,hisgrid,nQSOProgress,ncontest,lapcqonly,navg0,nqf)
call timer('dec_q65 ',1)
return
diff --git a/lib/mskrtd.f90 b/lib/mskrtd.f90 index e169b288..068f6c40 100755 --- a/lib/mskrtd.f90 +++ b/lib/mskrtd.f90 @@ -16,8 +16,8 @@ subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,hiscall, & character*4 decsym !"&" for mskspd or "^" for long averages
character*37 msgreceived !Decoded message
character*37 msglast,msglastswl !Used for dupechecking
- character*80 line !Formatted line with UTC dB T Freq Msg
- character*12 mycall,hiscall
+ character*(*) line !Formatted line with UTC dB T Freq Msg
+ character*(*) mycall,hiscall
character*37 recent_shmsgs(NSHMEM)
character*(*) datadir
@@ -70,15 +70,19 @@ subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,hiscall, & msglastswl=' '
nsnrlast=-99
nsnrlastswl=-99
- mycall13=mycall//' '
- dxcall13=hiscall//' '
+! mycall13=mycall//' '
+! dxcall13=hiscall//' '
+ mycall13=' '
+ dxcall13=' '
+ mycall13(1:12)=mycall(1:12)
+ dxcall13(1:12)=hiscall(1:12)
first=.false.
endif
fc=nrxfreq
! Reset if mycall or dxcall changes
- if(mycall13(1:12).ne.mycall .or. dxcall13(1:12).ne.hiscall) first=.true.
+ if(mycall13(1:12).ne.mycall(1:12) .or. dxcall13(1:12).ne.hiscall(1:12)) first=.true.
! Dupe checking setup
if(nutc00.ne.nutc0 .or. tsec.lt.tsec0) then ! reset dupe checker
@@ -90,7 +94,7 @@ subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,hiscall, & endif
tframe=float(NSPM)/12000.0
- line=char(0)
+ line(1:1)=char(0)
msgreceived=' '
max_iterations=10
niterations=0
diff --git a/lib/packjt.f90 b/lib/packjt.f90 index 8b471a0f..99e80fa8 100755 --- a/lib/packjt.f90 +++ b/lib/packjt.f90 @@ -338,7 +338,7 @@ subroutine packbits(dbits,nsymd,m0,sym) if(text) go to 900
! OK, we have a properly formatted grid locator
- 40 call grid2deg(grid//'mm',dlong,dlat)
+ 40 call grid2deg(grid//'mm55',dlong,dlat)
long=int(dlong)
lat=int(dlat+ 90.0)
ng=((long+180)/2)*180 + lat
@@ -872,7 +872,7 @@ subroutine packbits(dbits,nsymd,m0,sym) character*6 grid
- call grid2deg(grid,xlong,xlat)
+ call grid2deg(grid//'55',xlong,xlat)
nlong=nint(xlong)
nlat=nint(xlat)
k=0
diff --git a/lib/pctile.f90 b/lib/pctile.f90 index f7dba238..e5458ed9 100755 --- a/lib/pctile.f90 +++ b/lib/pctile.f90 @@ -3,6 +3,10 @@ subroutine pctile(x,npts,npct,xpct) real x(npts)
real,allocatable :: tmp(:)
+ if(npts.lt.0 .or. npct.lt.0 .or. npct.gt.100) then
+ xpct=1.0
+ go to 900
+ endif
allocate(tmp(npts))
tmp=x
@@ -11,6 +15,7 @@ subroutine pctile(x,npts,npct,xpct) if(j.lt.1) j=1
if(j.gt.npts) j=npts
xpct=tmp(j)
+ deallocate(tmp)
- return
+900 return
end subroutine pctile
diff --git a/lib/peakup.f90 b/lib/peakup.f90 index 8e5aedaf..95b1cdd3 100755 --- a/lib/peakup.f90 +++ b/lib/peakup.f90 @@ -1,7 +1,9 @@ subroutine peakup(ym,y0,yp,dx)
- b=(yp-ym)/2.0
- c=(yp+ym-2.0*y0)/2.0
+ real*4 b,c,dx,yp,ym,y0
+
+ b=(yp-ym)
+ c=(yp+ym-2.0*y0)
dx=-b/(2.0*c)
return
diff --git a/lib/prog_args.f90 b/lib/prog_args.f90 index 0b94c4b3..abb7cd7e 100755 --- a/lib/prog_args.f90 +++ b/lib/prog_args.f90 @@ -1,4 +1,6 @@ MODULE prog_args
CHARACTER(len=80) :: shm_key
- CHARACTER(len=500) :: exe_dir = '.', data_dir = '.', temp_dir = '.'
+ CHARACTER(len=500) :: exe_dir = '.', data_dir = '.', temp_dir = '.', &
+ share_dir = '.' !ft8md added share_dir
+ LOGICAL :: lquiet = .false.
END MODULE prog_args
diff --git a/lib/q65_decode.f90 b/lib/q65_decode.f90 index 7af3a368..fa3be337 100755 --- a/lib/q65_decode.f90 +++ b/lib/q65_decode.f90 @@ -33,7 +33,7 @@ contains subroutine decode(this,callback,iwave,nqd0,nutc,ntrperiod,nsubmode,nfqso, &
ntol,ndepth,nfa0,nfb0,lclearave,single_decode,lagain,max_drift0, &
lnewdat0,emedelay,mycall,hiscall,hisgrid,nQSOprogress,ncontest, &
- lapcqonly,navg0)
+ lapcqonly,navg0,nqf)
! Top-level routine that organizes the decoding of Q65 signals
! Input: iwave Raw data, i*2
@@ -55,9 +55,13 @@ contains use, intrinsic :: iso_c_binding
use q65 !Shared variables
use prog_args
+ use types
- parameter (NMAX=300*12000) !Max TRperiod is 300 s
+ parameter (NMAX=300*12000) !Max TRperiod is 300 s
+ parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode
+
class(q65_decoder), intent(inout) :: this
+
procedure(q65_decode_callback) :: callback
character(len=12) :: mycall, hiscall !Used for AP decoding
character(len=6) :: hisgrid
@@ -70,19 +74,26 @@ contains character*80 fmt
integer*2 iwave(NMAX) !Raw data
real, allocatable :: dd(:) !Raw data
+ real xdtdecodes(100)
+ real f0decodes(100)
integer dat4(13) !Decoded message as 12 6-bit integers
integer dgen(13)
+ integer nqf(20)
+ integer stageno !Added by W3SZ
+ integer time
logical lclearave,lnewdat0,lapcqonly,unpk77_success
logical single_decode,lagain
- complex, allocatable :: c00(:) !Analytic signal, 6000 Sa/s
- complex, allocatable :: c0(:) !Analytic signal, 6000 Sa/s
- integer stageno !Added by W3SZ
- stageno=0
+ complex c00(0:3600000) !Analytic signal, 6000 Sa/s
+ type(q3list) callers(MAX_CALLERS)
+ save c00
! Start by setting some parameters and allocating storage for large arrays
call sec0(0,tdecode)
+ stageno=0
ndecodes=0
decodes=' '
+ f0decodes=0.
+ xdtdecodes=0.
nfa=nfa0
nfb=nfb0
nqd=nqd0
@@ -97,9 +108,30 @@ contains nfft1=ntrperiod*12000
nfft2=ntrperiod*6000
npasses=1
+ nhist2=0
if(lagain) ndepth=ior(ndepth,3) !Use 'Deep' for manual Q65 decodes
dxcall13=hiscall ! initialize for use in packjt77
mycall13=mycall
+ if(ncontest.eq.1) then
+! NA VHF, WW-Digi, or ARRL Digi Contest
+ open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', &
+ form='unformatted')
+ read(24,end=2) nhist2
+ if(nhist2.ge.1 .and. nhist2.le.40) then
+ read(24,end=2) callers(1:nhist2)
+ now=time()
+ do i=1,nhist2
+ hours=(now - callers(i)%nsec)/3600.0
+ if(hours.gt.24.0) then
+ callers(i:nhist2-1)=callers(i+1:nhist2)
+ nhist2=nhist2-1
+ endif
+ enddo
+ else
+ nhist2=0
+ endif
+2 close(24)
+ endif
! Determine the T/R sequence: iseq=0 (even), or iseq=1 (odd)
n=nutc
@@ -111,8 +143,6 @@ contains if(lclearave) call q65_clravg
allocate(dd(npts))
- allocate (c00(0:nfft1-1))
- allocate (c0(0:nfft1-1))
if(lagain) then
call q65_hist(nfqso,dxcall=hiscall,dxgrid=hisgrid)
@@ -132,25 +162,37 @@ contains baud=12000.0/nsps
this%callback => callback
nFadingModel=1
- maxiters=33
- ibwa=max(1,int(1.8*log(baud*mode_q65)) + 1)
- ibwb=min(10,ibwa+2)
- if(iand(ndepth,3).ge.2) then
- ibwa=max(1,int(1.8*log(baud*mode_q65)) + 1)
- ibwb=min(10,ibwa+5)
- maxiters=67
- endif
+
+! ibwa=max(1,int(1.8*log(baud*mode_q65)) + 5)
+!### This needs work!
+ ibwa=1 !Q65-60A
+ if(mode_q65.eq.2) ibwa=3 !Q65-60B
+ if(mode_q65.eq.4) ibwa=8 !Q65-60C
+ if(mode_q65.eq.8) ibwa=8 !Q65-60D
+ if(mode_q65.eq.16) ibwa=8 !Q65-60E
+!###
+
+! ibwb=min(15,ibwa+4)
+ ibwb=min(15,ibwa+6)
+ maxiters=40
+ if(iand(ndepth,3).eq.2) maxiters=60
if(iand(ndepth,3).eq.3) then
- ibwa=max(1,ibwa-1)
- ibwb=min(10,ibwb+1)
+ ibwa=max(1,ibwa-2)
+ ibwb=min(15,ibwb+2)
maxiters=100
endif
+
! Generate codewords for full-AP list decoding
if(ichar(hiscall(1:1)).eq.0) hiscall=' '
if(ichar(hisgrid(1:1)).eq.0) hisgrid=' '
ncw=0
- if(nqd.eq.1 .or. lagain) then
- call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw)
+ if(nqd.eq.1 .or. lagain .or. ncontest.eq.1) then
+ if(ncontest.eq.1) then
+ call q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2, &
+ codewords,ncw)
+ else
+ call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw)
+ endif
endif
dgen=0
call q65_enc(dgen,codewords) !Initialize the Q65 codec
@@ -166,11 +208,9 @@ contains call timer('q65_dec0',0)
! Call top-level routine in q65 module: establish sync and try for a
! q3 or q0 decode.
- call q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
+ call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, &
emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
call timer('q65_dec0',1)
-! write(*,3001) '=a',nfqso,ntol,ndepth,xdt,f0,idec
-!3001 format(a2,3i5,f7.2,f7.1,i5)
if(idec.ge.0) then
dtdec=xdt !We have a q3 or q0 decode at nfqso
@@ -178,6 +218,9 @@ contains go to 100
endif
+ if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.16) go to 50
+ if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.0) go to 100
+
! Prepare for a single-period decode with iaptype = 0, 1, 2, or 4
jpk0=(xdt+1.0)*6000 !Index of nominal start of signal
if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences
@@ -200,11 +243,10 @@ contains read(c78,1060) apsymbols
endif
- call timer('q65loops',0)
+ call timer('q65loop1',0)
call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, &
xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec)
- call timer('q65loops',1)
-! write(*,3001) '=b',nfqso,ntol,ndepth,xdt,f0,idec
+ call timer('q65loop1',1)
if(idec.ge.0) then
dtdec=xdt1
f0dec=f1
@@ -215,11 +257,11 @@ contains if(iand(ndepth,16).eq.0 .or. navg(iseq).lt.2) go to 100
! There was no single-transmission decode. Try for an average 'q3n' decode.
-50 call timer('list_avg',0)
+50 iavg=1
+ call timer('list_avg',0)
! Call top-level routine in q65 module: establish sync and try for a q3
! decode, this time using the cumulative 's1a' symbol spectra.
- iavg=1
- call q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
+ call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, &
emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
call timer('list_avg',1)
@@ -236,7 +278,7 @@ contains call timer('q65_avg ',0)
iavg=2
- call q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
+ call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, &
emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
call timer('q65_avg ',1)
if(idec.ge.0) then
@@ -250,7 +292,7 @@ contains call timer('q65_dec0',0)
! Call top-level routine in q65 module: establish sync and try for a
! q3 or q0 decode.
- call q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
+ call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, &
emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
call timer('q65_dec0',1)
if(idec.ge.0) then
@@ -280,15 +322,21 @@ contains if(idupe.eq.0) then
ndecodes=min(ndecodes+1,100)
decodes(ndecodes)=decoded
- call q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2)
+ f0decodes(ndecodes)=f0dec
+ xdtdecodes(ndecodes)=dtdec
+ call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2)
nsnr=nint(snr2)
call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, &
idec,nused,ntrperiod)
- call q65_hist(nint(f0dec),msg0=decoded)
+ if(ncontest.eq.1) then
+ call q65_hist2(nint(f0dec),decoded,callers,nhist2)
+ else
+ call q65_hist(nint(f0dec),msg0=decoded)
+ endif
if(iand(ndepth,128).ne.0 .and. .not.lagain .and. &
int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg
call sec0(1,tdecode)
- open(22,file=trim(data_dir)//'/q65_decodes.dat',status='unknown', &
+ open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown', &
position='append',iostat=ios)
if(ios.eq.0) then
! Save decoding parameters to q65_decoded.dat, for later analysis.
@@ -298,13 +346,13 @@ contains if(c6.eq.' ') c6='<b> '
c4=hisgrid(1:4)
if(c4.eq.' ') c4='<b> '
- fmt='(i6.4,1x,a4,i5,4i2,6i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// &
+ fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// &
'1x,a6,1x,a6,1x,a4,1x,a)'
if(ntrperiod.le.30) fmt(5:5)='6'
if(idec.eq.3) nrc=0
write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest,idtbest, &
- ibw,ndistbest,nused,icand,ncand,nrc,ndepth,xdt,f0,snr2,plog, &
- tdecode,mycall(1:6),c6,c4,trim(decoded)
+ ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc,ndepth,xdt, &
+ f0,snr2,plog,tdecode,mycall(1:6),c6,c4,trim(decoded)
close(22)
endif
endif
@@ -317,6 +365,26 @@ contains snr1=candidates(icand,1)
xdt= candidates(icand,2)
f0 = candidates(icand,3)
+ do i=1,ndecodes
+ fdiff=f0-f0decodes(i)
+ if(fdiff.gt.-baud*mode_q65 .and. fdiff.lt.65*baud*mode_q65) go to 800
+ enddo
+
+!### TEST REGION
+ if(ncontest.eq.-1) then
+ call timer('q65_dec0',0)
+! Call top-level routine in q65 module: establish sync and try for a
+! q3 or q0 decode.
+ call q65_dec0(iavg,iwave,ntrperiod,nint(f0),ntol,lclearave, &
+ emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
+ call timer('q65_dec0',1)
+ if(idec.ge.0) then
+ dtdec=xdt !We have a q3 or q0 decode at f0
+ f0dec=f0
+ go to 200
+ endif
+ endif
+!###
jpk0=(xdt+1.0)*6000 !Index of nominal start of signal
if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences
if(jpk0.lt.0) jpk0=0
@@ -329,6 +397,8 @@ contains if(lapcqonly) npasses=1
iaptype=0
do ipass=0,npasses !Loop over AP passes
+! write(*,3001) nutc,icand,ipass,f0,xdt,snr1
+!3001 format('a',i5.4,2i3,3f7.1)
apmask=0 !Try first with no AP information
apsymbols=0
if(ipass.ge.1) then
@@ -341,10 +411,10 @@ contains read(c78,1060) apsymbols
endif
- call timer('q65loops',0)
+ call timer('q65loop2',0)
call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, &
xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec)
- call timer('q65loops',1)
+ call timer('q65loop2',1)
! write(*,3001) '=e',nfqso,ntol,ndepth,xdt,f0,idec
if(idec.ge.0) then
dtdec=xdt1
@@ -365,15 +435,21 @@ contains if(idupe.eq.0) then
ndecodes=min(ndecodes+1,100)
decodes(ndecodes)=decoded
- call q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2)
+ f0decodes(ndecodes)=f0dec
+ call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2)
nsnr=nint(snr2)
call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, &
idec,nused,ntrperiod)
- call q65_hist(nint(f0dec),msg0=decoded)
+ if(ncontest.eq.1) then
+ call q65_hist2(nint(f0dec),decoded,callers,nhist2)
+ else
+ call q65_hist(nint(f0dec),msg0=decoded)
+ endif
if(iand(ndepth,128).ne.0 .and. .not.lagain .and. &
int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg
call sec0(1,tdecode)
- open(22,file=trim(data_dir)//'/q65_decodes.dat',status='unknown', &
+ ios=1
+ open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown',&
position='append',iostat=ios)
if(ios.eq.0) then
! Save decoding parameters to q65_decoded.dat, for later analysis.
@@ -383,20 +459,45 @@ contains if(c6.eq.' ') c6='<b> '
c4=hisgrid(1:4)
if(c4.eq.' ') c4='<b> '
- fmt='(i6.4,1x,a4,i5,4i2,6i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// &
+ fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// &
'1x,a6,1x,a6,1x,a4,1x,a)'
if(ntrperiod.le.30) fmt(5:5)='6'
if(idec.eq.3) nrc=0
- write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest,idtbest, &
- ibw,ndistbest,nused,icand,ncand,nrc,ndepth,xdt,f0,snr2,plog, &
- tdecode,mycall(1:6),c6,c4,trim(decoded)
+ write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest, &
+ idtbest,ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc, &
+ ndepth,xdt,f0,snr2,plog,tdecode,mycall(1:6),c6,c4, &
+ trim(decoded)
close(22)
endif
endif
endif
+800 continue
enddo ! icand
if(iavg.eq.0 .and.navg(iseq).ge.2 .and. iand(ndepth,16).ne.0) go to 50
-900 return
+
+900 if(ncontest.ne.1 .or. lagain) go to 999
+ if(ntrperiod.ne.60 .or. nsubmode.ne.0) go to 999
+
+! This is first time here, and we're running Q65-60A in NA VHF Contest mode.
+! Return a list of potential sync frequencies at which to try q3 decoding.
+
+ k=0
+ nqf=0
+ bw=baud*mode_q65*65
+ do i=1,ncand
+! snr1=candidates(i,1)
+! xdt= candidates(i,2)
+ f0 = candidates(i,3)
+ do j=1,ndecodes ! Already decoded one at or near this frequency?
+ fj=f0decodes(j)
+ if(f0.gt.fj-5.0 .and. f0.lt.fj+bw+5.0) go to 990
+ enddo
+ k=k+1
+ nqf(k)=nint(f0)
+990 continue
+ enddo
+
+999 return
end subroutine decode
end module q65_decode
diff --git a/lib/qra/q65/q65.c b/lib/qra/q65/q65.c index 853a0696..189573d3 100755 --- a/lib/qra/q65/q65.c +++ b/lib/qra/q65/q65.c @@ -306,7 +306,7 @@ int q65_intrinsics_fastfading(q65_codec_ds *pCodec, return Q65_DECODE_INVPARAMS; // invalid pCodec pointer
- if (submode<0 || submode>4)
+ if (submode<0 || submode>5)
return Q65_DECODE_INVPARAMS; // invalid submode
// As the symbol duration in q65 is different than in QRA64,
diff --git a/lib/qra/q65/q65.f90 b/lib/qra/q65/q65.f90 index 3cb27545..6bfeef76 100755 --- a/lib/qra/q65/q65.f90 +++ b/lib/qra/q65/q65.f90 @@ -2,8 +2,8 @@ module q65 parameter (NSTEP=8) !Number of time bins per symbol in s1, s1a, s1b
parameter (PLOG_MIN=-242.0) !List decoding threshold
- integer nsave,nlist,LL0,iz0,jz0
- integer listutc(10)
+ integer iz0,jz0
+! integer listutc(10)
integer apsym0(58),aph10(10)
integer apmask1(78),apsymbols1(78)
integer apmask(13),apsymbols(13)
@@ -12,23 +12,22 @@ module q65 integer codewords(63,206)
integer ibwa,ibwb,ncw,nsps,mode_q65,nfa,nfb,nqd
integer idfbest,idtbest,ibw,ndistbest,maxiters,max_drift
- integer istep,nsmo,lag1,lag2,npasses,nused,iseq,ncand,nrc
+ integer istep,nsmo,lag1,lag2,npasses,iseq,ncand,nrc
integer i0,j0
integer navg(0:1)
logical lnewdat
real candidates(20,3) !snr, xdt, and f0 of top candidates
- real, allocatable :: s1raw(:,:) !Symbol spectra, 1/8-symbol steps
real, allocatable :: s1(:,:) !Symbol spectra w/suppressed peaks
- real, allocatable :: s1w(:,:) !Symbol spectra w/suppressed peaks !w3sz added
+ real, allocatable :: s1w(:,:) !Symbol spectra w/suppressed peaks (W3SZ)
real, allocatable,save :: s1a(:,:,:) !Cumulative symbol spectra
- real, allocatable,save :: ccf2(:) !Max CCF(freq) at any lag, single seq
- real, allocatable,save :: ccf2_avg(:) !Like ccf2, but for accumulated average
+ real, allocatable,save :: ccf2(:) !Max CCF(freq) at any lag (orange curve)
+ real, allocatable,save :: ccf2_avg(:) !Like ccf2, but for avg (red curve)
real sync(85) !sync vector
real df,dtstep,dtdec,f0dec,ftol,plog,drift
contains
-subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
+subroutine q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, &
emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno)
! Top-level routine in q65 module
@@ -41,7 +40,6 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & ! ntrperiod T/R sequence length (s)
! nfqso Target frequency (Hz)
! ntol Search range around nfqso (Hz)
-! ndepth Requested decoding depth
! lclearave Flag to clear the accumulating array
! emedelay Extra delay for EME signals
! Output: xdt Time offset from nominal (s)
@@ -68,7 +66,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & real, allocatable :: s3(:,:) !Data-symbol energies s3(LL,63)
real, allocatable :: ccf1(:) !CCF(freq) at fixed lag (red)
data first/.true./
- save first
+ save first,LL0
integer w3t
integer w3f
@@ -76,7 +74,6 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & integer stageno
NN=63
- if(nutc+ndepth.eq.-999) stop !Silence compiler warnings
! Set some parameters and allocate storage for large arrays
irc=-2
@@ -95,7 +92,8 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & ftol=ntol
ia=ntol/df
ia2=max(ia,10*mode_q65,nint(100.0/df))
- nsmo=int(0.7*mode_q65*mode_q65)
+! nsmo=int(0.7*mode_q65*mode_q65)
+ nsmo=int(0.5*mode_q65*mode_q65)
if(nsmo.lt.1) nsmo=1
if(first) then !Generate the sync vector
sync=-22.0/63.0 !Sync tone OFF
@@ -107,8 +105,6 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & allocate(s3(-64:LL-65,63))
allocate(ccf1(-ia2:ia2))
if(LL.ne.LL0 .or. iz.ne.iz0 .or. jz.ne.jz0 .or. lclearave) then
- if(allocated(s1raw)) deallocate(s1raw)
- allocate(s1raw(iz,jz))
if(allocated(s1)) deallocate(s1)
allocate(s1(iz,jz))
if(allocated(s1a)) deallocate(s1a)
@@ -126,38 +122,28 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & lclearave=.false.
endif
ccf1=0.
- if(iavg.eq.0) ccf2_avg=0.
+ if(iavg.eq.0) ccf2=0.
dtstep=nsps/(NSTEP*12000.0) !Step size in seconds
lag1=-1.0/dtstep
lag2=1.0/dtstep + 0.9999
if(nsps.ge.3600 .and. emedelay.gt.0) lag2=5.5/dtstep + 0.9999 !Include EME
+ if(ntrperiod.eq.15 .and. nsps.ge.900 .and. emedelay.gt.0) lag2=4/dtstep + 0.9999 !EME Q65-15
j0=0.5/dtstep
if(nsps.ge.7200) j0=1.0/dtstep !Nominal start-signal index
s3=0.
+! if(iavg.eq.0 .and. lnewdat) then
if(iavg.eq.0) then
call timer('q65_syms',0)
! Compute symbol spectra with NSTEP time bins per symbol
call q65_symspec(iwave,ntrperiod*12000,iz,jz,s1)
call timer('q65_syms',1)
+! lnewdat=.false.
else
s1=s1a(:,:,iseq)
endif
i0=nint(nfqso/df) !Target QSO frequency
- ii1=max(1,i0-64)
- ii2=i0-65+LL
- call pctile(s1(ii1:ii2,1:jz),ii2-ii1+1*jz,45,base)
- s1=s1/base
- s1raw=s1
-
-! Apply fast AGC to the symbol spectra
- s1max=20.0 !Empirical choice
- do j=1,jz !### Maybe wrong way? ###
- smax=maxval(s1(ii1:ii2,j))
- if(smax.gt.s1max) s1(ii1:ii2,j)=s1(ii1:ii2,j)*s1max/smax
- enddo
-
dat4=0
if(ncw.gt.0 .and. iavg.le.1) then
! Try list decoding via "Deep Likelihood".
@@ -178,16 +164,14 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & ! Get 2d CCF and ccf2 using sync symbols only
if(iavg.eq.0) then
call timer('ccf_22a ',0)
- call q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
- f0a,xdta,ccf2)
+ call q65_ccf_22(s1,iz,jz,nfqso,ntol,ipk,jpk,f0a,xdta,ccf2)
call timer('ccf_22a ',1)
endif
! Get 2d CCF and ccf2_avg using sync symbols only
if(iavg.ge.1) then
call timer('ccf_22b ',0)
- call q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
- f0a,xdta,ccf2_avg)
+ call q65_ccf_22(s1,iz,jz,nfqso,ntol,ipk,jpk,f0a,xdta,ccf2_avg)
call timer('ccf_22b ',1)
endif
if(idec.lt.0) then
@@ -217,10 +201,8 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & if(i2.eq.-9999 .and. ccf1(-i).ge.0.5*smax) i2=-i
enddo
width=df*(i2-i1)
-
if(ncw.eq.0) ccf1=0.
-
- call q65_write_red(iz,xdt,ccf2_avg,ccf2)
+ call q65_write_red(iz,xdt,ccf2_avg,ccf2) !### Need this call for WSJT-X
if(idec.lt.0 .and. (iavg.eq.0 .or. iavg.eq.2)) then
call q65_dec_q012(s3,LL,snr2,dat4,idec,decoded)
@@ -286,12 +268,12 @@ subroutine q65_symspec(iwave,nmax,iz,jz,s1) integer*2 iwave(0:nmax-1) !Raw data
real s1(iz,jz)
- complex, allocatable :: c0(:) !Complex spectrum of symbol
+ complex c0(0:41472) !Largest requirement, Q65-300x
+ save c0
- allocate(c0(0:nsps-1))
nfft=nsps
fac=1/32767.0
- do j=1,jz !Compute symbol spectra at step size
+ do j=1,jz,2 !Compute symbol spectra at 2*step size
i1=(j-1)*istep
i2=i1+nsps-1
k=-1
@@ -301,7 +283,7 @@ subroutine q65_symspec(iwave,nmax,iz,jz,s1) k=k+1
c0(k)=fac*cmplx(xx,yy)
enddo
- c0(k+1:)=0.
+ c0(k+1:nfft-1)=0.
call four2a(c0,nfft,1,-1,0) !r2c FFT
do i=1,iz
s1(i,j)=real(c0(i))**2 + aimag(c0(i))**2
@@ -311,6 +293,8 @@ subroutine q65_symspec(iwave,nmax,iz,jz,s1) do i=1,nsmo
call smo121(s1(1:iz,j),iz)
enddo
+! Interpolate to fill in the skipped-over spectra.
+ if(j.ge.3) s1(1:iz,j-1)=0.5*(s1(1:iz,j-2)+s1(1:iz,j))
enddo
if(lnewdat) then
navg(iseq)=navg(iseq) + 1
@@ -481,14 +465,14 @@ subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & return
end subroutine q65_ccf_85
-subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
- f0,xdt,ccf2)
+subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ipk,jpk,f0,xdt,ccf2)
! Attempt synchronization using only the 22 sync symbols. Return ccf2
! for the "orange sync curve".
real s1(iz,jz)
real ccf2(iz) !Orange sync curve
+ real tmp(20,3)
real, allocatable :: xdt2(:)
real, allocatable :: s1avg(:)
integer, allocatable :: indx(:)
@@ -499,11 +483,11 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, & ia=max(nfa,100)/df
ib=min(nfb,4900)/df
- if(nqd.ne.1 .or. iavg.ne.0) max_drift=0
if(max_drift.ne.0) then
ia=max(nint(100/df),nint((nfqso-ntol)/df))
ib=min(nint(4900/df),nint((nfqso+ntol)/df))
endif
+ if(ia.ge.ib) ia=ib-ntol/df !Protect against wacky settings
do i=ia,ib
s1avg(i)=sum(s1(i,1:jz))
@@ -513,7 +497,9 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, & ibest=0
lagpk=0
lagbest=0
+ idrift_max=0
idrift_best=0
+
do i=ia,ib
ccfmax=0.
do lag=lag1,lag2
@@ -535,10 +521,13 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, & endif
enddo ! idrift
enddo ! lag
+
ccf2(i)=ccfmax
xdt2(i)=lagpk*dtstep
+
if(ccfmax.gt.ccfbest .and. abs(i*df-nfqso).le.ftol) then
ccfbest=ccfmax
+ snrbest=snr
ibest=i
lagbest=lagpk
idrift_best=idrift_max
@@ -556,28 +545,39 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, & ! Save parameters for best candidates
jzz=ib-ia+1
- call pctile(ccf2(ia:ib),jzz,40,base)
- ccf2=ccf2/base
call indexx(ccf2(ia:ib),jzz,indx)
+
+ call pctile(ccf2(ia:ib),jzz,50,ave)
+ call pctile(ccf2(ia:ib),jzz,84,base)
+ rms=base-ave
ncand=0
maxcand=20
do j=1,20
k=jzz-j+1
if(k.lt.1 .or. k.gt.iz) cycle
i=indx(k)+ia-1
- if(ccf2(i).lt.3.3) exit !Candidate limit
f=i*df
i3=max(1, i-mode_q65)
i4=min(iz,i+mode_q65)
biggest=maxval(ccf2(i3:i4))
if(ccf2(i).ne.biggest) cycle
+ snr=(ccf2(i)-ave)/rms
+ if(snr.lt.6.0) exit
ncand=ncand+1
- candidates(ncand,1)=ccf2(i)
+ candidates(ncand,1)=snr
candidates(ncand,2)=xdt2(i)
candidates(ncand,3)=f
if(ncand.ge.maxcand) exit
enddo
+! Resort the candidates back into frequency order
+ tmp(1:ncand,1:3)=candidates(1:ncand,1:3)
+ candidates=0.
+ call indexx(tmp(1:ncand,3),ncand,indx)
+ do i=1,ncand
+ candidates(i,1:3)=tmp(indx(i),1:3)
+ enddo
+
return
end subroutine q65_ccf_22
@@ -591,7 +591,7 @@ subroutine q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) integer dat4(13)
character c77*77,decoded*37
logical unpk77_success
-
+
nFadingModel=1
decoded=' '
call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob)
@@ -605,7 +605,7 @@ subroutine q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) irc=-1
endif
nrc=irc
-
+
return
end subroutine q65_dec1
@@ -672,16 +672,21 @@ subroutine q65_write_red(iz,xdt,ccf2_avg,ccf2) call q65_sync_curve(ccf2_avg,1,iz,rms1)
call q65_sync_curve(ccf2,1,iz,rms2)
+ i1=max(1,nint(nfa/df))
+ i2=min(iz,int(nfb/df))
+ y0=minval(ccf2(i1:i2))
+ y0_avg=minval(ccf2_avg(i1:i2))
+ g=0.4
+ g_avg=0.
+ if(navg(iseq).ge.2) g_avg=g
rewind 17
- write(17,1000) xdt,minval(ccf2_avg),maxval(ccf2_avg)
- do i=max(1,nint(nfa/df)),min(iz,int(nfb/df))
+ write(17,1000) xdt,g_avg*minval(ccf2_avg),g_avg*maxval(ccf2_avg)
+ do i=i1,i2
freq=i*df
- y1=ccf2_avg(i)
- if(y1.gt.10.0) y1=10.0 + 2.0*log10(y1/10.0)
- y2=ccf2(i)
- if(y2.gt.10.0) y2=10.0 + 2.0*log10(y2/10.0)
+ y1=g_avg*(ccf2_avg(i)-y0_avg)
+ y2=g*(ccf2(i)-y0)
write(17,1000) freq,y1,y2
-1000 format(3f10.3)
+1000 format(f10.3,2f15.6)
enddo
flush(17)
@@ -733,7 +738,7 @@ subroutine q65_bzap(s3,LL) return
end subroutine q65_bzap
-subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2)
+subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,snr2)
! Estimate SNR of a decoded transmission by aligning the spectra of
! all 85 symbols.
@@ -764,7 +769,7 @@ subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2) if(j.ge.1 .and. j.le.jz0) then
do i=1,iz0
ii=i+mode_q65*itone(k)
- if(ii.ge.1 .and. ii.le.iz0) spec(i)=spec(i) + s1raw(ii,j)
+ if(ii.ge.1 .and. ii.le.iz0) spec(i)=spec(i) + s1(ii,j)
enddo
endif
enddo
@@ -781,8 +786,6 @@ subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2) sig_area=sum(spec(ia+nsum:ib-nsum)-1.0)
w_equiv=sig_area/(smax-1.0)
snr2=db(max(1.0,sig_area)) - db(2500.0/df)
-! NB: No adjustment to SNR is now made for nused>1, because that process did
-! not seem to work as expected.
return
end subroutine q65_snr
@@ -841,4 +844,66 @@ subroutine q65_hist(if0,msg0,dxcall,dxgrid) 900 return
end subroutine q65_hist
+subroutine q65_hist2(nfreq,msg0,callers,nhist2)
+
+ use types
+ use prog_args
+ parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode
+ character*37 msg0,msg
+ type(q3list) callers(MAX_CALLERS)
+ character*6 c6
+ character*4 g4
+ logical newcall,isgrid
+
+ isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. &
+ g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. &
+ g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73'
+
+ msg=msg0
+ if(index(msg,'/').gt.0) goto 900 !Ignore messages with compound calls
+ i0=index(msg,' R ')
+ if(i0.ge.7) msg=msg(1:i0)//msg(i0+3:)
+ i1=index(msg,' ')
+ c6=' '
+ g4=' '
+ if(i1.ge.4 .and. i1.le.13) then
+ i2=index(msg(i1+1:),' ') + i1
+ c6=msg(i1+1:i2-1) !Extract DX call
+ g4=msg(i2+1:i2+4) !Extract DX grid
+ endif
+
+ newcall=.true.
+ do i=1,nhist2
+ if(callers(i)%call .eq. c6) then
+ newcall=.false.
+ callers(i)%nsec=time()
+ callers(i)%nfreq=nfreq
+ exit
+ endif
+ enddo
+
+ if(newcall .and. isgrid(g4)) then
+ if(nhist2.eq.MAX_CALLERS) then
+! Purge the oldest caller
+ callers(1:MAX_CALLERS-1)=callers(2:MAX_CALLERS)
+ nhist2=nhist2-1
+ endif
+ nhist2=nhist2+1
+ callers(nhist2)%call=c6
+ callers(nhist2)%grid=g4
+ callers(nhist2)%nsec=time()
+ callers(nhist2)%nfreq=nfreq
+ endif
+
+ if(nhist2.ge.1 .and. nhist2.le.40) then
+ open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', &
+ form='unformatted')
+ write(24) nhist2
+ write(24) callers(1:nhist2)
+ close(24)
+ endif
+
+900 return
+end subroutine q65_hist2
+
end module q65
diff --git a/lib/qra/q65/q65_encoding_modules.f90 b/lib/qra/q65/q65_encoding_modules.f90 index dc65588d..c1f765df 100755 --- a/lib/qra/q65/q65_encoding_modules.f90 +++ b/lib/qra/q65/q65_encoding_modules.f90 @@ -135,10 +135,9 @@ end subroutine get_q65crc12(mc2,ncrc1,ncrc2)
!
- character c12*12,c6*6
+ character c6*6
integer*1 mc(90),mc2(90),tmp(6)
integer*1 r(13),p(13)
- integer ncrc
! polynomial for 12-bit CRC 0xF01
data p/1,1,0,0,0,0,0,0,0,1,1,1,1/
@@ -170,7 +169,6 @@ subroutine get_q65_tones(msg37,codeword,itone) implicit none
character*37 msg37
character*77 c77
- character*12 c12
character*6 c6
integer codeword(65)
integer sync(22)
diff --git a/lib/qra/q65/q65_loops.f90 b/lib/qra/q65/q65_loops.f90 index 0fc987c9..c4f3f2f6 100755 --- a/lib/qra/q65/q65_loops.f90 +++ b/lib/qra/q65/q65_loops.f90 @@ -37,7 +37,7 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & if(iand(ndepth,3).eq.3) then
idfmax=5
idtmax=5
- maxdist=15
+ maxdist=5
endif
napmin=99
diff --git a/lib/qra/q65/q65_set_list.f90 b/lib/qra/q65/q65_set_list.f90 index 790c7f0c..0debe2c6 100755 --- a/lib/qra/q65/q65_set_list.f90 +++ b/lib/qra/q65/q65_set_list.f90 @@ -3,7 +3,7 @@ subroutine q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) parameter (MAX_NCW=206)
character*12 mycall,hiscall
character*6 hisgrid
- character*37 msg0,msg,msgsent
+ character*37 msg,msgsent
logical my_std,his_std
integer codewords(63,MAX_NCW)
integer itone(85)
@@ -45,7 +45,7 @@ subroutine q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) endif
endif
-10 call genq65(msg,0,msgsent,itone,i3,n3)
+ call genq65(msg,0,msgsent,itone,i3,n3)
i0=1
j=0
do k=1,85
diff --git a/lib/qra/q65/q65_set_list2.f90 b/lib/qra/q65/q65_set_list2.f90 new file mode 100755 index 00000000..76797a0e --- /dev/null +++ b/lib/qra/q65/q65_set_list2.f90 @@ -0,0 +1,70 @@ +subroutine q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2,codewords,ncw)
+
+ use types
+ parameter (MAX_NCW=206)
+ parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode
+ character*12 mycall,hiscall
+ character*6 hisgrid,c6
+ character*4 g4
+ character*37 msg,msgsent
+ logical std,isgrid
+ integer codewords(63,MAX_NCW)
+ integer itone(85)
+ integer isync(22)
+ type(q3list) callers(MAX_CALLERS)
+
+ data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/
+
+ isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. &
+ g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. &
+ g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73'
+
+ call stdcall(hiscall,std)
+ jmax=nhist2
+ if(std .and. isgrid(hisgrid(1:4))) then
+ jmax=min(MAX_CALLERS,nhist2+1)
+ do j=1,nhist2
+ if(callers(j)%call .eq. hiscall(1:6)) then
+ jmax=nhist2
+ exit
+ endif
+ enddo
+ endif
+
+ codewords(:,1)=0
+ i=1
+ do j=1,jmax
+ c6=callers(j)%call
+ g4=callers(j)%grid
+ if(j.eq.nhist2+1) then
+ c6=hiscall(1:6)
+ g4=hisgrid(1:4)
+ endif
+ do k=1,5
+ i=i+1
+ msg=trim(mycall)//' '//trim(c6)
+ j0=len(trim(msg))+1
+ if(k.eq.1) msg=msg(1:j0)//g4
+ if(k.eq.2) msg=msg(1:j0)//'R '//g4
+ if(k.eq.3) msg(j0:j0+3)=' RRR'
+ if(k.eq.4) msg(j0:j0+4)=' RR73'
+ if(k.eq.5) msg(j0:j0+2)=' 73'
+ call genq65(msg,0,msgsent,itone,i3,n3)
+ i0=1
+ jj=0
+ do kk=1,85
+ if(kk.eq.isync(i0)) then
+ i0=i0+1
+ cycle
+ endif
+ jj=jj+1
+ codewords(jj,i)=itone(kk) - 1
+ enddo
+! write(71,3001) i,j,k,codewords(1:13,i),trim(msg)
+!3001 format(3i3,2x,13i3,2x,a)
+ enddo
+ enddo
+ ncw=i
+
+ return
+end subroutine q65_set_list2
diff --git a/lib/qra/q65/q65sim.f90 b/lib/qra/q65/q65sim.f90 index fbbc68dd..d47d6a2e 100755 --- a/lib/qra/q65/q65sim.f90 +++ b/lib/qra/q65/q65sim.f90 @@ -8,6 +8,7 @@ program q65sim type(hdr) h !Header for .wav file
integer*2 iwave(NMAX) !Generated waveform
integer itone(85) !Channel symbols (values 0-65)
+ integer ntone(85,10) !Channel symbols for up to 10 messages
integer y(63) !Codeword
integer istart !averaging compatible start seconds
integer imins !minutes for 15s period timestamp
@@ -17,19 +18,20 @@ program q65sim complex cdat(NMAX) !Generated complex waveform
complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading
complex z
- real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq
- character msg*37,fname*17,csubmode*1,arg*12
- character msgsent*37
+ real*8 f00,f0,dt,twopi,phi,dphi,baud,fsample,freq
+ character fname*17,csubmode*1,arg*12,c2*2
+ character*37 msg,msgsent,imsg(10)
nargs=iargc()
- if(nargs.ne.10) then
- print*,'Usage: q65sim "msg" A-E freq fDop DT f1 Stp TRp Nfile SNR'
- print*,'Example: q65sim "K1ABC W9XYZ EN37" A 1500 0.0 0.0 0.0 1 60 1 -26'
+ if(nargs.ne.11) then
+ print*,'Usage: q65sim "msg" A-F freq fDop DT f1 Stp TRp Nsig Nfile SNR'
+ print*,'Example: q65sim "K1ABC W9XYZ EN37" A 1500 0.0 0.0 0.0 1 60 1 1 -26'
print*,'Example: q65sim "ST" A 1500 0.0 0.0 0.0 1 60 1 -26'
print*,' fDop = Doppler spread'
print*,' f1 = Drift or Doppler rate (Hz/min)'
print*,' Stp = Step size (Hz)'
print*,' Stp = 0 implies no Doppler tracking'
+ print*,' Nsig = number of generated signals, 1 - 10'
print*,' Creates filenames which increment to permit averaging in first period'
print*,' If msg = ST program produces a single tone at freq'
go to 999
@@ -38,7 +40,7 @@ program q65sim call getarg(2,csubmode)
mode65=2**(ichar(csubmode)-ichar('A'))
call getarg(3,arg)
- read(arg,*) f0
+ read(arg,*) f00
call getarg(4,arg)
read(arg,*) fspread
call getarg(5,arg)
@@ -50,8 +52,10 @@ program q65sim call getarg(8,arg)
read(arg,*) ntrperiod
call getarg(9,arg)
- read(arg,*) nfiles
+ read(arg,*) nsig
call getarg(10,arg)
+ read(arg,*) nfiles
+ call getarg(11,arg)
read(arg,*) snrdb
if(ntrperiod.eq.15) then
@@ -79,22 +83,39 @@ program q65sim nsym=85 !Number of channel symbols
mode65=2**(ichar(csubmode) - ichar('A'))
- ichk=0
- call genq65(msg,ichk,msgsent,itone,i3,n3)
+
+ imsg(1)=msg
+ if(nsig.ge.2) then
+ i0=index(msg,' ')
+ i0=i0 + index(msg(i0+1:),' ')-2
+ do i=1,nsig
+ c2=char(ichar('A')+i-1)//char(ichar('A')+i-1)
+ imsg(i)=msg(1:i0-1)//c2//msg(i0+2:)
+ enddo
+ endif
- j=0
- do i=1,85
- if(itone(i).gt.0) then
- j=j+1
- y(j)=itone(i)-1
- endif
+ ichk=0
+ do i=1,nsig
+ msg=imsg(i)
+ call genq65(msg,ichk,msgsent,itone,i3,n3)
+ ntone(:,i)=itone
enddo
- write(*,1001) y(1:13),y(1:13)
+
+ if(nsig.eq.1) then
+ j=0
+ do i=1,85
+ if(itone(i).gt.0) then
+ j=j+1
+ y(j)=itone(i)-1
+ endif
+ enddo
+ write(*,1001) y(1:13),y(1:13)
1001 format('Generated message'/'6-bit: ',13i3/'binary: ',13b6.6)
- write(*,1002) y
+ write(*,1002) y
1002 format(/'Codeword:'/(20i3))
- write(*,1003) itone
+ write(*,1003) itone
1003 format(/'Channel symbols:'/(20i3))
+ endif
baud=12000.d0/nsps !Keying rate (6.67 baud fot 15-s sequences)
h=default_header(12000,npts)
@@ -116,43 +137,54 @@ program q65sim open(10,file=trim(fname),access='stream',status='unknown')
xnoise=0.
- cdat=0.
if(snrdb.lt.90) then
do i=1,npts
xnoise(i)=gran() !Generate gaussian noise
enddo
endif
+ cdat=0.
bandwidth_ratio=2500.0/6000.0
sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb)
if(snrdb.gt.90.0) sig=1.0
- write(*,1020) ifile,ntrperiod,f0,csubmode,snrdb,fspread,xdt,f1,nstp,trim(msgsent)
-1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,1x,f6.2,2f6.1,i4,2x,a)
- phi=0.d0
- dphi=0.d0
- k=(xdt+0.5)*12000 !Start audio at t=xdt+0.5 s (TR=15 and 30 s)
- if(ntrperiod.ge.60) k=(xdt+1.0)*12000 !TR 60+ at t = xdt + 1.0 s
- isym0=-99
- do i=1,npts !Add this signal into cdat()
- isym=i/nsps + 1
- if(isym.gt.nsym) exit
- if(isym.ne.isym0) then
- freq_drift=f1*i*dt/60.0
- if(nstp.ne.0) freq_drift=freq_drift - nstp*nint(freq_drift/nstp)
- if (msg(1:2).eq.'ST') then
- freq = f0 + freq_drift
- else
- freq = f0 + freq_drift + itone(isym)*baud*mode65
- endif
- dphi=twopi*freq*dt
- isym0=isym
+ write(*,1020) ifile,ntrperiod,f00,csubmode,snrdb,fspread,xdt,f1,nstp,trim(msgsent)
+1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,1x,f6.2,2f6.1,i4,2x,a)
+
+ n=65.0*baud*mode65/100.0 + 0.9999
+ nfstep=100*n
+ nf1=1500 - nfstep*(nsig-1)/2
+ do n=1,nsig
+ f0=f00
+ if(nsig.ge.2) then
+ f0=nf1 + (n-1)*nfstep
+ itone=ntone(:,n)
endif
- phi=phi + dphi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- z=cmplx(cos(xphi),sin(xphi))
- k=k+1
- if(k.ge.1) cdat(k)=cdat(k) + sig*z
+ phi=0.d0
+ dphi=0.d0
+ k=(xdt+0.5)*12000 !Start audio at t=xdt+0.5 s (TR=15 and 30 s)
+ if(ntrperiod.ge.60) k=(xdt+1.0)*12000 !TR 60+ at t = xdt + 1.0 s
+ isym0=-99
+ do i=1,npts !Add this signal into cdat()
+ isym=i/nsps + 1
+ if(isym.gt.nsym) exit
+ if(isym.ne.isym0) then
+ freq_drift=f1*i*dt/60.0
+ if(nstp.ne.0) freq_drift=freq_drift - nstp*nint(freq_drift/nstp)
+ if (msg(1:2).eq.'ST') then
+ freq = f0 + freq_drift
+ else
+ freq = f0 + freq_drift + itone(isym)*baud*mode65
+ endif
+ dphi=twopi*freq*dt
+ isym0=isym
+ endif
+ phi=phi + dphi
+ if(phi.gt.twopi) phi=phi-twopi
+ xphi=phi
+ z=cmplx(cos(xphi),sin(xphi))
+ k=k+1
+ if(k.ge.1) cdat(k)=cdat(k) + sig*z
+ enddo
enddo
if(fspread.ne.0) then !Apply specified Doppler spread
@@ -190,14 +222,20 @@ program q65sim fac=sqrt(1.0/avep)
cspread=fac*cspread !Normalize to constant avg power
cdat=cspread*cdat !Apply Rayleigh fading
-
-! do i=0,nfft-1
-! p=real(cspread(i))**2 + aimag(cspread(i))**2
-! write(14,3010) i,p,cspread(i)
-!3010 format(i8,3f12.6)
-! enddo
endif
+! psig=0.
+! pnoise=0.
+! do i=1,npts
+! if(i.gt.12000 .and. i.lt.624000) then
+! psig=psig + aimag(cdat(i))**2
+! pnoise=pnoise + xnoise(i)*xnoise(i)
+! endif
+! enddo
+! pnoise=pnoise*bandwidth_ratio
+! snr_2500=db(psig/pnoise) !Calibration confirmation!
+! print*,'SNR_2500:',snr_2500
+
dat=aimag(cdat) + xnoise !Add generated AWGN noise
fac=32767.0
if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts))
diff --git a/lib/save_echo_params.f90 b/lib/save_echo_params.f90 index 500a997c..5be3f2f5 100755 --- a/lib/save_echo_params.f90 +++ b/lib/save_echo_params.f90 @@ -1,28 +1,36 @@ -subroutine save_echo_params(nDopTotal,nDopAudio,nfrit,f1,fspread,id2,idir)
+subroutine save_echo_params(nDopTotal,nDopAudio,nfrit,f1,fspread,ntonespacing, &
+ itone,id2,idir)
- integer*2 id2(10)
- integer*2 id2a(10)
+ integer*2 id2(15),id2a(15)
+ integer*4 itone(6)
+ integer*1 itone0(6)
equivalence (nDopTotal0,id2a(1))
equivalence (nDopAudio0,id2a(3))
equivalence (nfrit0,id2a(5))
equivalence (f10,id2a(7))
equivalence (fspread0,id2a(9))
-
+ equivalence (ntonespacing0,id2a(11))
+ equivalence (itone0,id2a(13))
+
if(idir.gt.0) then
nDopTotal0=nDopTotal
nDopAudio0=nDopAudio
nfrit0=nfrit
f10=f1
fspread0=fspread
+ ntonespacing0=ntonespacing
+ itone0=itone
id2=id2a
else
id2a=id2
- id2(1:10)=0
nDopTotal=nDopTotal0
nDopAudio=nDopAudio0
nfrit=nfrit0
f1=f10
fspread=fspread0
+ ntonespacing=ntonespacing0
+ if(any(itone0.lt.0) .or. any(itone0.gt.36)) itone0=0
+ itone=itone0
endif
return
diff --git a/lib/spec64.f90 b/lib/spec64.f90 index 1839b340..7a269923 100755 --- a/lib/spec64.f90 +++ b/lib/spec64.f90 @@ -1,7 +1,7 @@ subroutine spec64(c0,npts,nsps,mode_q65,jpk,s3,LL,NN)
parameter (MAXFFT=20736)
- complex c0(0:npts-1) !Complex spectrum of dd()
+ complex c0(0:npts-1) !Complex spectrum of dd()
complex cs(0:MAXFFT-1) !Complex symbol spectrum
real s3(LL,NN) !Synchronized symbol spectra
real xbase0(LL),xbase(LL)
@@ -24,7 +24,8 @@ subroutine spec64(c0,npts,nsps,mode_q65,jpk,s3,LL,NN) if(jb.gt.npts-1) jb=npts-1
nz=jb-ja
cs(0:nz)=c0(ja:jb)
- if(nz.lt.nfft-1) cs(nz+1:)=0.
+! if(nz.lt.nfft-1) cs(nz+1:)=0.
+ if(nz.lt.nfft-1 .and. nz.ge.0) cs(nz+1:)=0. !Avoid a potential bounds error with Q65-15 EME
call four2a(cs,nsps,1,-1,1) !c2c FFT to frequency
do ii=1,LL
i=ii-65+mode_q65 !mode_q65 = 1 2 4 8 16 for Q65 A B C D E
diff --git a/lib/sumsim.f90 b/lib/sumsim.f90 index f07d2ec3..24cca29a 100755 --- a/lib/sumsim.f90 +++ b/lib/sumsim.f90 @@ -35,7 +35,7 @@ program sumsim fac=1.0/nargs
iwave(1:npts)=nint(fac*wave(1:npts))
- open(12,file='000000_0000.wav',access='stream',status='unknown')
+ open(12,file='000001_0000.wav',access='stream',status='unknown')
write(12) h,iwave(1:npts)
close(12)
diff --git a/lib/sun.f90 b/lib/sun.f90 index db258bb2..cfdc3a13 100755 --- a/lib/sun.f90 +++ b/lib/sun.f90 @@ -50,7 +50,7 @@ subroutine sun(y,m,DD,UT,lon,lat,RA,Dec,LST,Az,El,mjd,day) MM = mod(356.0470d0 + 0.9856002585d0 * d + 360000.d0,360.d0)
Ls = mod(w+MM+720.0,360.0)
- EE = MM + e*rad*sin(MM/rad) * (1.0 + e*cos(M/rad))
+ EE = MM + e*rad*sin(MM/rad) * (1.0 + e*cos(MM/rad))
EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.0 - e*cos(EE/rad))
xv = cos(EE/rad) - e
diff --git a/lib/superfox/foxgen2.f90 b/lib/superfox/foxgen2.f90 new file mode 100755 index 00000000..a6831dc8 --- /dev/null +++ b/lib/superfox/foxgen2.f90 @@ -0,0 +1,75 @@ +subroutine foxgen2(nslots,cmsg,line,foxcall)
+
+! Parse old-style Fox messages to extract the necessary pieces for a SuperFox
+! transmission.
+
+ use packjt77
+ character*120 line
+ character*40 cmsg(5) !Old-style Fox messages are here
+ character*37 msg
+ character*26 sfmsg
+ character*13 mycall
+ character*11 foxcall
+ character*4 mygrid
+ character*6 hiscall_1,hiscall_2
+ character*4 rpt1,rpt2
+ character*13 w(19)
+ integer nw(19)
+ integer ntype !Message type: 0 Free Text
+ ! 1 CQ MyCall MyGrid
+ ! 2 Call_1 MyCall RR73
+ ! 3 Call_1 MyCall rpt1
+ ! 4 Call_1 RR73; Call_2 <MyCall> rpt2
+
+ if(nslots.lt.1 .or. nslots.gt.5) return
+ k=0
+ do i=1,nslots
+ hiscall_1=''
+ hiscall_2=''
+ mycall=''
+ mygrid=''
+ rpt1=''
+ rpt2=''
+ msg=cmsg(i)(1:37)
+ call split77(msg,nwords,nw,w)
+ ntype=0
+ if(msg(1:3).eq.'CQ ') then
+ ntype=1
+ mycall=w(2)(1:12)
+ mygrid=w(3)(1:4)
+ else if(index(msg,';').gt.0) then
+ ntype=4
+ hiscall_1=w(1)(1:6)
+ hiscall_2=w(3)(1:6)
+ rpt1='RR73'
+ rpt2=w(5)(1:4)
+ mycall=w(4)(2:nw(4)-1)
+ else if(index(msg,' RR73').gt.0) then
+ ntype=2
+ hiscall_1=w(1)(1:6)
+ mycall=w(2)(1:12)
+ rpt1='RR73'
+ else if(nwords.eq.3 .and. nw(3).eq.3 .and. &
+ (w(3)(1:1).eq.'-' .or. w(3)(1:1).eq.'+')) then
+ ntype=3
+ hiscall_1=w(1)(1:6)
+ mycall=w(2)(1:12)
+ rpt1=w(3)(1:4)
+ endif
+
+ k=k+1
+ if(ntype.le.3) call sfox_assemble(ntype,k,msg(1:26),mycall,mygrid,line)
+ if(ntype.eq.4) then
+ sfmsg=w(1)(1:nw(1))//' '//mycall(1:len(trim(mycall))+1)//'RR73'
+ call sfox_assemble(2,k,sfmsg,mycall,mygrid,line)
+ sfmsg=w(3)(1:nw(3))//' '//mycall(1:len(trim(mycall))+1)//w(5)(1:3)
+ k=k+1
+ call sfox_assemble(3,k,sfmsg,mycall,mygrid,line)
+ endif
+ enddo
+
+ call sfox_assemble(ntype,11,msg(1:26),mycall,mygrid,line) !k=11 to finish up
+ foxcall=mycall(1:11)
+
+ return
+end subroutine foxgen2
diff --git a/lib/superfox/ft8_params.f90 b/lib/superfox/ft8_params.f90 new file mode 100755 index 00000000..bd228bde --- /dev/null +++ b/lib/superfox/ft8_params.f90 @@ -0,0 +1,12 @@ +! LDPC (174,91) code
+parameter (KK=91) !Information bits (77 + CRC14)
+parameter (ND=58) !Data symbols
+parameter (NS=21) !Sync symbols (3 @ Costas 7x7)
+parameter (NN=NS+ND) !Total channel symbols (79)
+parameter (NSPS=1920) !Samples per symbol at 12000 S/s
+parameter (NZ=NSPS*NN) !Samples in full 15 s waveform (151,680)
+parameter (NMAX=15*12000) !Samples in iwave (180,000)
+parameter (NFFT1=2*NSPS, NH1=NFFT1/2) !Length of FFTs for symbol spectra
+parameter (NSTEP=NSPS/4) !Rough time-sync step size
+parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps)
+parameter (NDOWN=60) !Downsample factor
diff --git a/lib/superfox/gtag.f90 b/lib/superfox/gtag.f90 new file mode 100755 index 00000000..a21c5b40 --- /dev/null +++ b/lib/superfox/gtag.f90 @@ -0,0 +1,3 @@ + integer ntag
+ data ntag/z"1234567"/
+ !-----------------------------------------------------------------------
diff --git a/lib/superfox/julian.f90 b/lib/superfox/julian.f90 new file mode 100755 index 00000000..8d8b7411 --- /dev/null +++ b/lib/superfox/julian.f90 @@ -0,0 +1,39 @@ +module julian
+
+contains
+
+ integer*8 function itime8()
+
+ implicit integer (a-z)
+! 1 2 3 4 5 6 7
+ integer it(8) !y m d nmin h m s
+ integer*8 secday
+ data secday/86400/
+
+ call date_and_time(values=it)
+ iyr=it(1)
+ imo=it(2)
+ iday=it(3)
+ days=JD(iyr,imo,iday) - 2440588 !Days since epoch Jan 1, 1970
+ ih=it(5)
+ im=it(6)-it(4) !it(4) corrects for time zone
+ is=it(7)
+ nsec=3600*ih + 60*im + is
+ itime8=days*secday + nsec
+
+ return
+ end function itime8
+
+ integer function JD(I,J,K)
+
+! Return Julian Date for I=year, J=month, K=day
+! Reference: Fliegel and Van Flandern, Comm. ACM 11, 10, 1968
+
+ JD = K - 32075 + 1461*(I + 4800 + (J - 14)/12)/4 &
+ + 367*(J - 2 - (J - 14)/12*12)/12 - 3 &
+ *((I + 4900 + (J - 14)/12)/100)/4
+
+ return
+ end function JD
+
+end module julian
diff --git a/lib/superfox/popen_module.f90 b/lib/superfox/popen_module.f90 new file mode 100755 index 00000000..3b937175 --- /dev/null +++ b/lib/superfox/popen_module.f90 @@ -0,0 +1,103 @@ +!*******************************************************************************
+!>
+! A simple module for `popen`.
+
+ module popen_module
+
+ use,intrinsic :: iso_c_binding
+
+ implicit none
+
+ private
+
+ ! interfaces to C functions
+ interface
+
+ function popen(command, mode) bind(C,name='popen')
+ !! initiate pipe streams to or from a process
+ import :: c_char, c_ptr
+ implicit none
+ character(kind=c_char),dimension(*) :: command
+ character(kind=c_char),dimension(*) :: mode
+ type(c_ptr) :: popen
+ end function popen
+
+ function fgets(s, siz, stream) bind(C,name='fgets')
+ !! get a string from a stream
+ import :: c_char, c_ptr, c_int
+ implicit none
+ type (c_ptr) :: fgets
+ character(kind=c_char),dimension(*) :: s
+ integer(kind=c_int),value :: siz
+ type(c_ptr),value :: stream
+ end function fgets
+
+ function pclose(stream) bind(C,name='pclose')
+ !! close a pipe stream to or from a process
+ import :: c_ptr, c_int
+ implicit none
+ integer(c_int) :: pclose
+ type(c_ptr),value :: stream
+ end function pclose
+
+ end interface
+
+ public :: c2f_string, get_command_as_string
+
+contains
+
+ !*******************************************************************************
+ !>
+ ! Convert a C string to a Fortran string.
+
+ function c2f_string(c) result(f)
+
+ character(len=*),intent(in) :: c !! C string
+ character(len=:),allocatable :: f !! Fortran string
+
+ integer :: i
+
+ i = index(c,c_null_char)
+
+ if (i<=0) then
+ f = c
+ else if (i==1) then
+ f = ''
+ else if (i>1) then
+ f = c(1:i-1)
+ end if
+
+ end function c2f_string
+
+ !*******************************************************************************
+ !>
+ ! Return the result of the command as a string.
+
+ function get_command_as_string(command) result(str)
+
+ character(len=*),intent(in) :: command !! the command to run
+ character(len=:),allocatable :: str !! the result of that command
+
+ integer,parameter :: buffer_length = 1000 !! read stream in chunks of this size
+
+ type(c_ptr) :: h !! for `popen`
+ integer(c_int) :: istat !! `pclose` status
+ character(kind=c_char,len=buffer_length) :: line !! buffer to read from `fgets`
+
+ str = ''
+ h = c_null_ptr
+ h = popen(command//c_null_char,'r'//c_null_char)
+
+ if (c_associated(h)) then
+ do while (c_associated(fgets(line,buffer_length,h)))
+ str = str//c2f_string(line)
+ end do
+ istat = pclose(h)
+ end if
+
+ end function get_command_as_string
+
+!*******************************************************************************
+ end module popen_module
+!*******************************************************************************
+
diff --git a/lib/superfox/qpc/dbgprintf.c b/lib/superfox/qpc/dbgprintf.c new file mode 100755 index 00000000..f17d4e47 --- /dev/null +++ b/lib/superfox/qpc/dbgprintf.c @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------------
+// dbgprintf.c
+// Functions for printing debug information
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+// ------------------------------------------------------------------------------
+
+#include "dbgprintf.h"
+
+// print functions for debug purposes
+void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize)
+{
+ int k;
+
+ printf("%s=", name);
+ for (k = 0; k < vsize; k++) {
+ if ((k & 0x0F) == 0)
+ printf("\n");
+ printf("%02X ", v[k]);
+ }
+ printf("\n");
+}
+
+void dbgprintf_vector_float(const char* name, const float* v, int vsize)
+{
+ int k;
+
+ printf("%s=", name);
+ for (k = 0; k < vsize; k++) {
+ if ((k & 0x07) == 0)
+ printf("\n");
+ printf("%10.3f ", v[k]);
+ }
+ printf("\n");
+}
+
+void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows)
+{
+ int k;
+ int j;
+
+ printf("%s=\n", name);
+ for (j = 0; j < nrows; j++) {
+ printf("r%d:", j);
+ for (k = 0; k < vsize; k++) {
+ if ((k & 0x07) == 0)
+ printf("\n");
+ printf("%7.3f ", v[k]);
+ }
+ printf("\n");
+ v += vsize;
+ }
+}
diff --git a/lib/superfox/qpc/dbgprintf.h b/lib/superfox/qpc/dbgprintf.h new file mode 100755 index 00000000..8133042b --- /dev/null +++ b/lib/superfox/qpc/dbgprintf.h @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------
+// dbgprintf.h
+// Functions for printing debug information
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+// ------------------------------------------------------------------------------
+
+#ifndef _dbgprintf_h_
+#define _dbgprintf_h_
+
+// Define DBGPRINTF_ANYWAY
+// in order to print debug information also
+// when _DEBUG is not defined
+
+#define DBGPRINTF_ANYWAY
+
+#ifdef _DEBUG
+#define DBG_PRINTF
+#else
+#ifdef DBGPRINTF_ANYWAY
+#define DBG_PRINTF
+#endif
+#endif
+
+#include <stdio.h>
+
+// print functions for debug purposes
+#ifdef DBG_PRINTF
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize);
+ void dbgprintf_vector_float(const char* name, const float* v, int vsize);
+ void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows);
+
+#ifdef __cplusplus
+}
+#endif
+
+#else
+
+#define dbgprintf_vector_uchar(a,b)
+#define dbgprintf_vector_float(a,b)
+#define dbgprintf_rows_float(a, b, c, d)
+
+#endif
+
+#endif // _dbgprintf_h_
diff --git a/lib/superfox/qpc/nhash2.c b/lib/superfox/qpc/nhash2.c new file mode 100755 index 00000000..40bae20e --- /dev/null +++ b/lib/superfox/qpc/nhash2.c @@ -0,0 +1,383 @@ +/*
+
+ File name: nhash2.c
+
+ *------------------------------------------------------------------------------
+ *
+ * This file is part of the WSPR application, Weak Signal Propogation Reporter
+ *
+ * File Name: nhash.c
+ * Description: Functions to produce 32-bit hashes for hash table lookup
+ *
+ * Copyright (C) 2008-2014 Joseph Taylor, K1JT
+ * License: GNU GPL v3+
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ * Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Files: lookup3.c
+ * Copyright: Copyright (C) 2006 Bob Jenkins <bob_jenkins@burtleburtle.net>
+ * License: public-domain
+ * You may use this code any way you wish, private, educational, or commercial.
+ * It's free.
+ *
+ *-------------------------------------------------------------------------------
+*/
+
+/*
+These are functions for producing 32-bit hashes for hash table lookup.
+hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
+are externally useful functions. Routines to test the hash are included
+if SELF_TEST is defined. You can use this free for any purpose. It's in
+the public domain. It has no warranty.
+
+You probably want to use hashlittle(). hashlittle() and hashbig()
+hash byte arrays. hashlittle() is is faster than hashbig() on
+little-endian machines. Intel and AMD are little-endian machines.
+On second thought, you probably want hashlittle2(), which is identical to
+hashlittle() except it returns two 32-bit hashes for the price of one.
+You could implement hashbig2() if you wanted but I haven't bothered here.
+
+If you want to find a hash of, say, exactly 7 integers, do
+ a = i1; b = i2; c = i3;
+ mix(a,b,c);
+ a += i4; b += i5; c += i6;
+ mix(a,b,c);
+ a += i7;
+ final(a,b,c);
+then use c as the hash value. If you have a variable length array of
+4-byte integers to hash, use hashword(). If you have a byte array (like
+a character string), use hashlittle(). If you have several byte arrays, or
+a mix of things, see the comments above hashlittle().
+
+Why is this so big? I read 12 bytes at a time into 3 4-byte integers,
+then mix those integers. This is fast (you can do a lot more thorough
+mixing with 12*3 instructions on 3 integers than you can with 3 instructions
+on 1 byte), but shoehorning those bytes into integers efficiently is messy.
+*/
+
+#define SELF_TEST 1
+
+#include <stdio.h> /* defines printf for tests */
+#include <time.h> /* defines time_t for timings in the test */
+#include "nhash2.h"
+//#include <sys/param.h> /* attempt to define endianness */
+//#ifdef linux
+//# include <endian.h> /* attempt to define endianness */
+//#endif
+
+#define HASH_LITTLE_ENDIAN 1
+
+#define hashsize(n) ((uint32_t)1<<(n))
+#define hashmask(n) (hashsize(n)-1)
+#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+
+/*
+-------------------------------------------------------------------------------
+mix -- mix 3 32-bit values reversibly.
+
+This is reversible, so any information in (a,b,c) before mix() is
+still in (a,b,c) after mix().
+
+If four pairs of (a,b,c) inputs are run through mix(), or through
+mix() in reverse, there are at least 32 bits of the output that
+are sometimes the same for one pair and different for another pair.
+This was tested for:
+* pairs that differed by one bit, by two bits, in any combination
+ of top bits of (a,b,c), or in any combination of bottom bits of
+ (a,b,c).
+* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
+ the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
+ is commonly produced by subtraction) look like a single 1-bit
+ difference.
+* the base values were pseudorandom, all zero but one bit set, or
+ all zero plus a counter that starts at zero.
+
+Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that
+satisfy this are
+ 4 6 8 16 19 4
+ 9 15 3 18 27 15
+ 14 9 3 7 17 3
+Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
+for "differ" defined as + with a one-bit base and a two-bit delta. I
+used http://burtleburtle.net/bob/hash/avalanche.html to choose
+the operations, constants, and arrangements of the variables.
+
+This does not achieve avalanche. There are input bits of (a,b,c)
+that fail to affect some output bits of (a,b,c), especially of a. The
+most thoroughly mixed value is c, but it doesn't really even achieve
+avalanche in c.
+
+This allows some parallelism. Read-after-writes are good at doubling
+the number of bits affected, so the goal of mixing pulls in the opposite
+direction as the goal of parallelism. I did what I could. Rotates
+seem to cost as much as shifts on every machine I could lay my hands
+on, and rotates are much kinder to the top and bottom bits, so I used
+rotates.
+-------------------------------------------------------------------------------
+*/
+#define mix(a,b,c) \
+{ \
+ a -= c; a ^= rot(c, 4); c += b; \
+ b -= a; b ^= rot(a, 6); a += c; \
+ c -= b; c ^= rot(b, 8); b += a; \
+ a -= c; a ^= rot(c,16); c += b; \
+ b -= a; b ^= rot(a,19); a += c; \
+ c -= b; c ^= rot(b, 4); b += a; \
+}
+
+/*
+-------------------------------------------------------------------------------
+final -- final mixing of 3 32-bit values (a,b,c) into c
+
+Pairs of (a,b,c) values differing in only a few bits will usually
+produce values of c that look totally different. This was tested for
+* pairs that differed by one bit, by two bits, in any combination
+ of top bits of (a,b,c), or in any combination of bottom bits of
+ (a,b,c).
+* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
+ the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
+ is commonly produced by subtraction) look like a single 1-bit
+ difference.
+* the base values were pseudorandom, all zero but one bit set, or
+ all zero plus a counter that starts at zero.
+
+These constants passed:
+ 14 11 25 16 4 14 24
+ 12 14 25 16 4 14 24
+and these came close:
+ 4 8 15 26 3 22 24
+ 10 8 15 26 3 22 24
+ 11 8 15 26 3 22 24
+-------------------------------------------------------------------------------
+*/
+#define final(a,b,c) \
+{ \
+ c ^= b; c -= rot(b,14); \
+ a ^= c; a -= rot(c,11); \
+ b ^= a; b -= rot(a,25); \
+ c ^= b; c -= rot(b,16); \
+ a ^= c; a -= rot(c,4); \
+ b ^= a; b -= rot(a,14); \
+ c ^= b; c -= rot(b,24); \
+}
+
+/*
+-------------------------------------------------------------------------------
+hashlittle() -- hash a variable-length key into a 32-bit value
+ k : the key (the unaligned variable-length array of bytes)
+ length : the length of the key, counting by bytes
+ initval : can be any 4-byte value
+Returns a 32-bit value. Every bit of the key affects every bit of
+the return value. Two keys differing by one or two bits will have
+totally different hash values.
+
+The best hash table sizes are powers of 2. There is no need to do
+mod a prime (mod is sooo slow!). If you need less than 32 bits,
+use a bitmask. For example, if you need only 10 bits, do
+ h = (h & hashmask(10));
+In which case, the hash table should have hashsize(10) elements.
+
+If you are hashing n strings (uint8_t **)k, do it like this:
+ for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);
+
+By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this
+code any way you wish, private, educational, or commercial. It's free.
+
+Use for hash table lookup, or anything where one collision in 2^^32 is
+acceptable. Do NOT use for cryptographic purposes.
+-------------------------------------------------------------------------------
+*/
+
+uint32_t nhash2( const void *key, uint64_t length, uint32_t initval)
+//int nhash( const char *key, int length, int initval)
+{
+ uint32_t a,b,c; /* internal state */
+ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
+
+ /* Set up the internal state */
+ a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
+
+ u.ptr = key;
+ if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
+ const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */
+
+ /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */
+ while (length > 12)
+ {
+ a += k[0];
+ b += k[1];
+ c += k[2];
+ mix(a,b,c);
+ length -= 12;
+ k += 3;
+ }
+
+ // printf("AAA %x %d %x %d\n",c,c,c&32767,c&32767);
+
+ /*----------------------------- handle the last (probably partial) block */
+ /*
+ * "k[2]&0xffffff" actually reads beyond the end of the string, but
+ * then masks off the part it's not allowed to read. Because the
+ * string is aligned, the masked-off tail is in the same word as the
+ * rest of the string. Every machine with memory protection I've seen
+ * does it on word boundaries, so is OK with this. But VALGRIND will
+ * still catch it and complain. The masking trick does make the hash
+ * noticably faster for short strings (like English words).
+ */
+#ifndef VALGRIND
+
+ switch(length)
+ {
+ case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
+ case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
+ case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
+ case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
+ case 8 : b+=k[1]; a+=k[0]; break;
+ case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
+ case 6 : b+=k[1]&0xffff; a+=k[0]; break;
+ case 5 : b+=k[1]&0xff; a+=k[0]; break;
+ case 4 : a+=k[0]; break;
+ case 3 : a+=k[0]&0xffffff; break;
+ case 2 : a+=k[0]&0xffff; break;
+ case 1 : a+=k[0]&0xff; break;
+ case 0 : return c; /* zero length strings require no mixing */
+ }
+
+#else /* make valgrind happy */
+
+ k8 = (const uint8_t *)k;
+ switch(length)
+ {
+ case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
+ case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
+ case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
+ case 9 : c+=k8[8]; /* fall through */
+ case 8 : b+=k[1]; a+=k[0]; break;
+ case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
+ case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
+ case 5 : b+=k8[4]; /* fall through */
+ case 4 : a+=k[0]; break;
+ case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
+ case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
+ case 1 : a+=k8[0]; break;
+ case 0 : return c;
+ }
+
+#endif /* !valgrind */
+
+ } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
+ const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
+ const uint8_t *k8;
+
+ /*--------------- all but last block: aligned reads and different mixing */
+ while (length > 12)
+ {
+ a += k[0] + (((uint32_t)k[1])<<16);
+ b += k[2] + (((uint32_t)k[3])<<16);
+ c += k[4] + (((uint32_t)k[5])<<16);
+ mix(a,b,c);
+ length -= 12;
+ k += 6;
+ }
+
+ /*----------------------------- handle the last (probably partial) block */
+ k8 = (const uint8_t *)k;
+ switch(length)
+ {
+ case 12: c+=k[4]+(((uint32_t)k[5])<<16);
+ b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
+ case 10: c+=k[4];
+ b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 9 : c+=k8[8]; /* fall through */
+ case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
+ case 6 : b+=k[2];
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 5 : b+=k8[4]; /* fall through */
+ case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
+ case 2 : a+=k[0];
+ break;
+ case 1 : a+=k8[0];
+ break;
+ case 0 : return c; /* zero length requires no mixing */
+ }
+
+ } else { /* need to read the key one byte at a time */
+ const uint8_t *k = (const uint8_t *)key;
+
+ /*--------------- all but the last block: affect some 32 bits of (a,b,c) */
+ while (length > 12)
+ {
+ a += k[0];
+ a += ((uint32_t)k[1])<<8;
+ a += ((uint32_t)k[2])<<16;
+ a += ((uint32_t)k[3])<<24;
+ b += k[4];
+ b += ((uint32_t)k[5])<<8;
+ b += ((uint32_t)k[6])<<16;
+ b += ((uint32_t)k[7])<<24;
+ c += k[8];
+ c += ((uint32_t)k[9])<<8;
+ c += ((uint32_t)k[10])<<16;
+ c += ((uint32_t)k[11])<<24;
+ mix(a,b,c);
+ length -= 12;
+ k += 12;
+ }
+
+ /*-------------------------------- last block: affect all 32 bits of (c) */
+ switch(length) /* all the case statements fall through */
+ {
+ case 12: c+=((uint32_t)k[11])<<24;
+ /* fall through */
+ case 11: c+=((uint32_t)k[10])<<16;
+ /* fall through */
+ case 10: c+=((uint32_t)k[9])<<8;
+ /* fall through */
+ case 9 : c+=k[8];
+ /* fall through */
+ case 8 : b+=((uint32_t)k[7])<<24;
+ /* fall through */
+ case 7 : b+=((uint32_t)k[6])<<16;
+ /* fall through */
+ case 6 : b+=((uint32_t)k[5])<<8;
+ /* fall through */
+ case 5 : b+=k[4];
+ /* fall through */
+ case 4 : a+=((uint32_t)k[3])<<24;
+ /* fall through */
+ case 3 : a+=((uint32_t)k[2])<<16;
+ /* fall through */
+ case 2 : a+=((uint32_t)k[1])<<8;
+ /* fall through */
+ case 1 : a+=k[0];
+ break;
+ case 0 : return c;
+ }
+ }
+
+ final(a,b,c);
+ return c;
+}
diff --git a/lib/superfox/qpc/nhash2.h b/lib/superfox/qpc/nhash2.h new file mode 100755 index 00000000..830e18ac --- /dev/null +++ b/lib/superfox/qpc/nhash2.h @@ -0,0 +1,22 @@ +#ifndef NHASH_H_
+#define NHASH_H_
+
+#ifdef Win32
+#include "win_stdint.h" /* defines uint32_t etc */
+#else
+#include <stddef.h>
+#include <stdint.h> /* defines uint32_t etc */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint32_t nhash( const void * key, uint64_t length, uint32_t initval);
+ //int nhash(const char *key, int length, int initval);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/superfox/qpc/np_qpc.c b/lib/superfox/qpc/np_qpc.c new file mode 100755 index 00000000..9398c43b --- /dev/null +++ b/lib/superfox/qpc/np_qpc.c @@ -0,0 +1,329 @@ +// ------------------------------------------------------------------------------
+// np_qpc.h
+// Q-Ary Polar Codes encoding/decoding functions
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
+
+#include "dbgprintf.h"
+#include "qpc_fwht.h"
+#include "np_qpc.h"
+
+// static constant / functions
+
+static const float knorm = 1.0f / QPC_Q;
+
+static float* pdf_conv(float *dst, float* pdf1, float* pdf2)
+{
+ // convolution between two pdf
+
+ float fwht_pdf1[QPC_Q];
+ float fwht_pdf2[QPC_Q];
+ int k;
+
+ qpc_fwht(fwht_pdf1, pdf1);
+ qpc_fwht(fwht_pdf2, pdf2);
+
+ for (k = 0; k < QPC_Q; k++)
+ fwht_pdf1[k] *= fwht_pdf2[k];
+
+ qpc_fwht(dst, fwht_pdf1);
+
+ for (k = 0; k < QPC_Q; k++)
+ dst[k] *= knorm;
+
+ return dst;
+}
+static void pdfarray_conv(float* dstarray, float* pdf1array, float* pdf2array, int numrows)
+{
+ int k;
+
+ // convolutions between rows of pdfs
+
+ for (k = 0; k < numrows; k++) {
+ pdf_conv(dstarray, pdf1array, pdf2array);
+ dstarray += QPC_Q;
+ pdf1array += QPC_Q;
+ pdf2array += QPC_Q;
+ }
+
+}
+
+static float _pdfuniform[QPC_Q];
+static const float* _pdf_uniform1();
+static const float* _pdf_uniform0();
+typedef const float*(*ptr_pdfuniform)(void);
+
+static ptr_pdfuniform _ptr_pdf_uniform = _pdf_uniform0;
+
+static const float* _pdf_uniform1()
+{
+ return _pdfuniform;
+};
+static const float* _pdf_uniform0()
+{
+ // compute uniform pdf once for all
+ int k;
+ for (k = 0; k < QPC_Q; k++)
+ _pdfuniform[k] = knorm;
+
+ // next call to _qpc_pdfuniform
+ // will be handled directly by _pqc_pdfuniform1
+ _ptr_pdf_uniform = _pdf_uniform1;
+
+ return _pdfuniform;
+};
+static const float* pdf_uniform()
+{
+ return _ptr_pdf_uniform();
+}
+
+static float * pdf_mul(float *dst, float* pdf1, float* pdf2)
+{
+ int k;
+ float v;
+ float norm = 0;
+ for (k = 0; k < QPC_Q; k++) {
+ v = pdf1[k] * pdf2[k];
+ dst[k] = v;
+ norm += v;
+ }
+ // if norm of the result is not positive
+ // return in dst a uniform distribution
+ if (norm <= 0)
+ memcpy(dst, pdf_uniform(), QPC_Q * sizeof(float));
+ else {
+ norm = 1.0f / norm;
+ for (k = 0; k < QPC_Q; k++)
+ dst[k] = dst[k] * norm;
+ }
+
+
+ return dst;
+}
+static void pdfarray_mul(float* dstarray, float* pdf1array, float* pdf2array, int numrows)
+{
+ int k;
+
+ // products between rows of pdfs
+
+ for (k = 0; k < numrows; k++) {
+ pdf_mul(dstarray, pdf1array, pdf2array);
+ dstarray += QPC_Q;
+ pdf1array += QPC_Q;
+ pdf2array += QPC_Q;
+ }
+}
+
+static float* pdf_convhard(float* dst, const float* pdf, unsigned char hd)
+{
+ // convolution between a pdf and a hard-decision feedback
+
+ int k;
+ for (k=0;k<QPC_Q;k++)
+ dst[k] = pdf[k^hd];
+
+ return dst;
+}
+static void pdfarray_convhard(float* dstarray, const float* pdfarray, const unsigned char *hdarray, int numrows)
+{
+ int k;
+
+ // hard convolutions between rows
+
+ for (k = 0; k < numrows; k++) {
+ pdf_convhard(dstarray, pdfarray, hdarray[k]);
+ dstarray += QPC_Q;
+ pdfarray += QPC_Q;
+ }
+}
+
+static unsigned char pdf_max(const float* pdf)
+{
+ int k;
+
+ unsigned char imax = 0;
+ float pdfmax = pdf[0];
+
+ for (k=1;k<QPC_Q;k++)
+ if (pdf[k] > pdfmax) {
+ pdfmax = pdf[k];
+ imax = k;
+ }
+
+ return imax;
+}
+
+// local stack functions ---------------------------------------
+static float _qpc_stack[QPC_N * QPC_Q * 2];
+static float* _qpc_stack_base = _qpc_stack;
+
+static float* _qpc_stack_push(int numfloats)
+{
+ float* addr = _qpc_stack_base;
+ _qpc_stack_base += numfloats;
+ return addr;
+}
+static void _qpc_stack_pop(int numfloats)
+{
+ _qpc_stack_base -= numfloats;
+}
+
+// qpc encoder function (internal use) ----------------------------------------------------------
+unsigned char* _qpc_encode(unsigned char* y, unsigned char* x)
+{
+ // Non recursive polar encoder
+ // Same architecture of a fast fourier transform
+ // in which the fft butteflies are replaced by the polar transform
+ // butterflies
+
+ int k, j, m;
+ int groups;
+ int bfypergroup;
+ int stepbfy;
+ int stepgroup;
+ int basegroup;
+ int basebfy;
+
+ memcpy(y, x, QPC_N);
+
+ for (k = 0; k < QPC_LOG2N; k++) {
+ groups = 1 << (QPC_LOG2N - 1 - k);
+ stepbfy = bfypergroup = 1 << k;
+ stepgroup = stepbfy << 1;
+ basegroup = 0;
+ for (j = 0; j < groups; j++) {
+ basebfy = basegroup;
+ for (m = 0; m < bfypergroup; m++) {
+ // polar transform
+ y[basebfy + stepbfy] = y[basebfy + stepbfy] ^ y[basebfy];
+ basebfy = basebfy + 1;
+ }
+ basegroup = basegroup + stepgroup;
+ }
+ }
+
+ return y;
+}
+
+// qpc polar decoder (internal use )--------------------------------------------------
+void _qpc_decode(unsigned char* xdec, unsigned char* ydec, const float* py, const unsigned char* f, const unsigned char* fsize, const int numrows)
+{
+
+ if (numrows == 1) {
+ if (fsize[0] == 0) {
+ // dbgprintf_vector_float("py", py, QPC_Q);
+
+ // frozen symbol
+ xdec[0] = pdf_max(py);
+ ydec[0] = f[0];
+ }
+ else {
+ // fsize = 1 => information symbol
+ xdec[0] = pdf_max(py);
+ ydec[0] = xdec[0];
+ }
+
+ }
+ else {
+
+ int k;
+ int nextrows = numrows >> 1;
+ int size = nextrows << QPC_LOG2Q;
+
+ // upper block variables
+ unsigned char* xdech = xdec + nextrows;
+ unsigned char* ydech = ydec + nextrows;
+ const unsigned char* fh = f + nextrows;
+ const unsigned char* fsizeh = fsize + nextrows;
+
+ // Step 1.
+ // stack and init variables used in the recursion
+
+ float* pyl = _qpc_stack_push(size);
+ memcpy(pyl, py, size * sizeof(float));
+
+ float* pyh = _qpc_stack_push(size);
+ memcpy(pyh, py + size, size * sizeof(float));
+
+ // Step 2. Recursion on upper block
+ // Forward pdf convolutions for the upper block
+ // (place in the lower part of py the convolution of lower and higher blocks)
+
+// float* pyh = py + size;
+// pdfarray_conv(py, pyl, pyh, nextrows); // convolution overwriting the lower block of py which is not needed
+
+ pdfarray_conv(pyh, pyl, pyh, nextrows);
+ _qpc_decode(xdech, ydech, pyh, fh, fsizeh, nextrows);
+
+ // Step 3. compute pdfs in the lower block
+ pdfarray_convhard(pyh, py+size, ydech,nextrows); // dst ptr must be different form src ptr
+ pdfarray_mul(pyl, pyl, pyh, nextrows);
+ // we don't need pyh anymore
+ _qpc_stack_pop(size);
+
+ // Step 4. Recursion on the lower block
+ _qpc_decode(xdec, ydec, pyl, f, fsize, nextrows);
+ // we don't need pyl anymore
+ _qpc_stack_pop(size);
+
+ // Step 5. Update backward results
+ // xdec is already ok, we need just to update ydech
+ for (k = 0; k < nextrows; k++)
+ ydech[k] = ydech[k] ^ ydec[k];
+
+ }
+
+
+}
+
+// Public encoding/decoding functions ------------------------------------------------
+void qpc_encode(unsigned char* y, const unsigned char* x)
+{
+
+ // map information symbols
+ int kk, pos;
+ for (kk = 0; kk < QPC_K; kk++) {
+ pos = qpccode.xpos[kk];
+ qpccode.f[pos] = x[kk];
+ }
+ // do polar encoding
+ _qpc_encode(y, qpccode.f);
+}
+void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py)
+{
+ int k;
+ unsigned char x[QPC_N];
+
+ // set the first py row with know frozen (punctured) symbol
+ if (qpccode.np < qpccode.n) {
+ // assume that we punctured only the first output symbol
+ memset(py, 0, QPC_Q * sizeof(float));
+ py[qpccode.f[0]] = 1.0f;
+ }
+
+ // decode
+ _qpc_decode(x, ydec, py, qpccode.f, qpccode.fsize, QPC_N);
+
+ // demap information symbols
+ for (k = 0; k < QPC_K; k++)
+ xdec[k] = x[qpccode.xpos[k]];
+
+}
diff --git a/lib/superfox/qpc/np_qpc.h b/lib/superfox/qpc/np_qpc.h new file mode 100755 index 00000000..a93bf1bc --- /dev/null +++ b/lib/superfox/qpc/np_qpc.h @@ -0,0 +1,62 @@ +// ------------------------------------------------------------------------------
+// np_qpc.h
+// Q-Ary Polar Codes encoding/decoding functions
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+
+
+#ifndef _np_qpc_h_
+#define _np_qpc_h_
+
+#define QPC_LOG2N 7 // log2(codeword length) (not punctured)
+#define QPC_N (1<<QPC_LOG2N) // codeword length (not punctured)
+#define QPC_LOG2Q 7 // bits per symbol
+#define QPC_Q (1<<QPC_LOG2Q) // alphabet size
+#define QPC_K 50 // number of information symbols
+
+
+typedef struct {
+ int n; // codeword length (unpunctured)
+ int np; // codeword length (punctured)
+ int k; // number of information symbols
+ int q; // alphabet size
+ int xpos[QPC_N]; // info symbols mapping/demapping tables
+ unsigned char f[QPC_N]; // frozen symbols values
+ unsigned char fsize[QPC_N]; // frozen symbol flag (fsize==0 => frozen)
+} qpccode_ds;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void qpc_encode(unsigned char* y, const unsigned char* x);
+ void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py);
+
+ unsigned char* _qpc_encode(unsigned char* y, unsigned char* x);
+ void _qpc_decode(unsigned char* xdec, unsigned char* ydec,
+ const float* py, const unsigned char* f, const unsigned char* fsize,
+ const int numrows);
+
+ extern qpccode_ds qpccode;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _np_qpc_h_
diff --git a/lib/superfox/qpc/np_rnd.c b/lib/superfox/qpc/np_rnd.c new file mode 100755 index 00000000..1d792c6b --- /dev/null +++ b/lib/superfox/qpc/np_rnd.c @@ -0,0 +1,135 @@ +// ------------------------------------------------------------------------------
+// np_rnd.c
+// Functions to generate random numbers with uniform/gaussian probability distributions
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+#include "np_rnd.h"
+
+#if _WIN32 // note the underscore: without it, it's not msdn official!
+ // Windows (x64 and x86)
+ #include <windows.h> // required only for GetTickCount(...)
+ #define K_RAND_MAX UINT_MAX
+#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */
+ #include <stdlib.h>
+ #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF
+ #define K_RAND_MAX 0x7FFFFFFF // that's the max number
+ // generated by lrand48
+#else
+ #error "No good quality PRNG found"
+#endif
+
+
+void np_normrnd_real(float *dst, int nitems, float mean, float stdev)
+{
+ // for odd or even nitems
+
+ unsigned int r;
+ float phi=0, u=0;
+ int set = 0;
+ float scalephi = (M_2PI / (1.0f + K_RAND_MAX));
+ float scaleu = (1.0f / (1.0f + K_RAND_MAX));
+
+
+ while (nitems--)
+ if (set==1) {
+ // generate a second normally distributed number
+ *dst++ = sinf(phi)*u*stdev+mean;
+ set = 0;
+ }
+ else {
+ // generate a uniform distributed phase phi in the range [0,2*PI)
+ rand_s((unsigned int*)&r); phi = scalephi * r;
+
+ // generate a uniform distributed random number u in the range (0,1]
+ rand_s((unsigned int*)&r); u = scaleu * (1.0f + r);
+
+ // generate normally distributed number
+ u = (float)sqrt(-2.0f * log(u));
+ *dst++ = cosf(phi) * u * stdev + mean;
+
+ set=1;
+ }
+}
+
+void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev)
+{
+ // as qpc_normrnd_real, but generates always nitems complex numbers (2*nitems reals)
+
+ unsigned int r;
+ float phi = 0, u = 0;
+ // JHT int set = 0;
+ float scalephi = (M_2PI / (1.0f + K_RAND_MAX));
+ float scaleu = (1.0f / (1.0f + K_RAND_MAX));
+
+ while (nitems--) {
+ // generate a uniform distributed phase phi in the range [0,2*PI)
+ rand_s((unsigned int*)&r); phi = scalephi * r;
+
+ // generate a uniform distributed random number u in the range (0,1]
+ rand_s((unsigned int*)&r); u = scaleu * (1.0f + r);
+
+ // generate normally distributed real and imaginary parts
+ u = (float)sqrt(-2.0f * log(u));
+ *dst++ = cosf(phi) * u * stdev + mean;
+ *dst++ = sinf(phi) * u * stdev + mean;
+ }
+}
+
+void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize)
+{
+ // generate uniform unsigned int random numbers in the range [0..nsetsize)
+
+ unsigned int r;
+ float u;
+ float scaleu = (1.0f / (1.0f + K_RAND_MAX));
+
+ while (nitems--) {
+ rand_s((unsigned int*)&r); u = scaleu * nsetsize * r;
+ *dst++ = (unsigned int)floorf(u);
+ }
+
+}
+void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize)
+{
+ // generate uniform unsigned char random numbers in the range [0..nsetsize)
+
+ unsigned int r;
+ float u;
+ float scaleu = (1.0f / (1.0f + K_RAND_MAX));
+
+ while (nitems--) {
+ rand_s((unsigned int*)&r); u = scaleu * nsetsize * r;
+ *dst++ = (unsigned char)floorf(u);
+ }
+
+}
+
+void np_unifrnd(float* dst, int nitems, float fmax)
+{
+ // generate uniform float random numbers in the range [0..fmax)
+
+ unsigned int r;
+ float u;
+ float scaleu = (1.0f / (1.0f + K_RAND_MAX));
+
+ while (nitems--) {
+ rand_s((unsigned int*)&r); u = scaleu * fmax * r;
+ *dst++ = u;
+ }
+
+}
diff --git a/lib/superfox/qpc/np_rnd.h b/lib/superfox/qpc/np_rnd.h new file mode 100755 index 00000000..6bc27b20 --- /dev/null +++ b/lib/superfox/qpc/np_rnd.h @@ -0,0 +1,59 @@ +// ------------------------------------------------------------------------------
+// np_rnd.h
+// Functions to generate random numbers with uniform/gaussian probability distributions
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef _np_rnd_h_
+#define _np_rnd_h_
+
+#define _CRT_RAND_S
+#include <stdlib.h>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+#define M_2PI (2.0f*(float)M_PI)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// generate a random array of real numbers with a gaussian distribution of given mean and stdev
+void np_normrnd_real(float *dst, int nitems, float mean, float stdev);
+
+// generate a random array of nitems complex numbers with a gaussian distribution of given mean and stdev
+void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev);
+
+// generate a random array of nitems unsigned int numbers with uniform distribution
+// in the range [0 .. nsetsize)
+void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize);
+
+// generate a random array of nitems unsigned chars numbers with uniform distribution
+// in the range [0 .. nsetsize)
+void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize);
+
+// generate a random array of nitems float numbers with uniform distribution
+// in the range [0 .. fmax)
+void np_unifrnd(float* dst, int nitems, float fmax);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _np_rnd_h_
+
diff --git a/lib/superfox/qpc/qpc_fwht.c b/lib/superfox/qpc/qpc_fwht.c new file mode 100755 index 00000000..92cb7c2b --- /dev/null +++ b/lib/superfox/qpc/qpc_fwht.c @@ -0,0 +1,233 @@ +// ------------------------------------------------------------------------------
+// qpc_fwht.c
+// Fast Walsh-Hadamard Transforms for q-ary polar codes
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+#include "qpc_fwht.h"
+
+static void _qpc_sumdiff8_16(float* y, float* t)
+{
+ y[0] = t[0] + t[16];
+ y[16] = t[0] - t[16];
+
+ y[1] = t[1] + t[17];
+ y[17] = t[1] - t[17];
+
+ y[2] = t[2] + t[18];
+ y[18] = t[2] - t[18];
+
+ y[3] = t[3] + t[19];
+ y[19] = t[3] - t[19];
+
+ y[4] = t[4] + t[20];
+ y[20] = t[4] - t[20];
+
+ y[5] = t[5] + t[21];
+ y[21] = t[5] - t[21];
+
+ y[6] = t[6] + t[22];
+ y[22] = t[6] - t[22];
+
+ y[7] = t[7] + t[23];
+ y[23] = t[7] - t[23];
+
+}
+static void _qpc_sumdiff8_32(float* y, float* t)
+{
+ y[0] = t[0] + t[32];
+ y[32] = t[0] - t[32];
+
+ y[1] = t[1] + t[33];
+ y[33] = t[1] - t[33];
+
+ y[2] = t[2] + t[34];
+ y[34] = t[2] - t[34];
+
+ y[3] = t[3] + t[35];
+ y[35] = t[3] - t[35];
+
+ y[4] = t[4] + t[36];
+ y[36] = t[4] - t[36];
+
+ y[5] = t[5] + t[37];
+ y[37] = t[5] - t[37];
+
+ y[6] = t[6] + t[38];
+ y[38] = t[6] - t[38];
+
+ y[7] = t[7] + t[39];
+ y[39] = t[7] - t[39];
+
+}
+static void _qpc_sumdiff8_64(float* y, float* t)
+{
+ y[0] = t[0] + t[64];
+ y[64] = t[0] - t[64];
+
+ y[1] = t[1] + t[65];
+ y[65] = t[1] - t[65];
+
+ y[2] = t[2] + t[66];
+ y[66] = t[2] - t[66];
+
+ y[3] = t[3] + t[67];
+ y[67] = t[3] - t[67];
+
+ y[4] = t[4] + t[68];
+ y[68] = t[4] - t[68];
+
+ y[5] = t[5] + t[69];
+ y[69] = t[5] - t[69];
+
+ y[6] = t[6] + t[70];
+ y[70] = t[6] - t[70];
+
+ y[7] = t[7] + t[71];
+ y[71] = t[7] - t[71];
+
+}
+
+float* qpc_fwht8(float* y, float* x)
+{
+ float t[8];
+
+ // first stage
+ y[0] = x[0] + x[1];
+ y[1] = x[0] - x[1];
+
+ y[2] = x[2] + x[3];
+ y[3] = x[2] - x[3];
+
+ y[4] = x[4] + x[5];
+ y[5] = x[4] - x[5];
+
+ y[6] = x[6] + x[7];
+ y[7] = x[6] - x[7];
+
+ // second stage
+ t[0] = y[0] + y[2];
+ t[2] = y[0] - y[2];
+
+ t[1] = y[1] + y[3];
+ t[3] = y[1] - y[3];
+
+ t[4] = y[4] + y[6];
+ t[6] = y[4] - y[6];
+
+ t[5] = y[5] + y[7];
+ t[7] = y[5] - y[7];
+
+ // third stage
+ y[0] = t[0] + t[4];
+ y[4] = t[0] - t[4];
+
+ y[1] = t[1] + t[5];
+ y[5] = t[1] - t[5];
+
+ y[2] = t[2] + t[6];
+ y[6] = t[2] - t[6];
+
+ y[3] = t[3] + t[7];
+ y[7] = t[3] - t[7];
+
+ return y;
+}
+float* qpc_fwht16(float* y, float* x)
+{
+ float t[16];
+
+ qpc_fwht8(t, x);
+ qpc_fwht8(t + 8, x + 8);
+
+ y[0] = t[0] + t[8];
+ y[8] = t[0] - t[8];
+
+ y[1] = t[1] + t[9];
+ y[9] = t[1] - t[9];
+
+ y[2] = t[2] + t[10];
+ y[10] = t[2] - t[10];
+
+ y[3] = t[3] + t[11];
+ y[11] = t[3] - t[11];
+
+ y[4] = t[4] + t[12];
+ y[12] = t[4] - t[12];
+
+ y[5] = t[5] + t[13];
+ y[13] = t[5] - t[13];
+
+ y[6] = t[6] + t[14];
+ y[14] = t[6] - t[14];
+
+ y[7] = t[7] + t[15];
+ y[15] = t[7] - t[15];
+
+ return y;
+
+}
+float* qpc_fwht32(float* y, float* x)
+{
+ float t[32];
+
+ qpc_fwht16(t, x);
+ qpc_fwht16(t + 16, x + 16);
+
+ _qpc_sumdiff8_16(y, t);
+ _qpc_sumdiff8_16(y + 8, t + 8);
+
+ return y;
+}
+float* qpc_fwht64(float* y, float* x)
+{
+ float t[64];
+
+ qpc_fwht32(t, x);
+ qpc_fwht32(t + 32, x + 32);
+
+ _qpc_sumdiff8_32(y, t);
+ _qpc_sumdiff8_32(y + 8, t + 8);
+ _qpc_sumdiff8_32(y + 16, t + 16);
+ _qpc_sumdiff8_32(y + 24, t + 24);
+
+ return y;
+}
+float* qpc_fwht128(float* y, float* x)
+{
+ float t[128];
+
+ qpc_fwht64(t, x);
+ qpc_fwht64(t + 64, x + 64);
+
+ _qpc_sumdiff8_64(y, t);
+ _qpc_sumdiff8_64(y + 8, t + 8);
+ _qpc_sumdiff8_64(y + 16, t + 16);
+ _qpc_sumdiff8_64(y + 24, t + 24);
+ _qpc_sumdiff8_64(y + 32, t + 32);
+ _qpc_sumdiff8_64(y + 40, t + 40);
+ _qpc_sumdiff8_64(y + 48, t + 48);
+ _qpc_sumdiff8_64(y + 56, t + 56);
+
+ return y;
+}
+
+// functions over pdfs used by the decoder -----------------------------------------------------------
+
+
+
+
diff --git a/lib/superfox/qpc/qpc_fwht.h b/lib/superfox/qpc/qpc_fwht.h new file mode 100755 index 00000000..733af7d4 --- /dev/null +++ b/lib/superfox/qpc/qpc_fwht.h @@ -0,0 +1,57 @@ +// ------------------------------------------------------------------------------
+// qpc_fwht.h
+// Fast Walsh-Hadamard Transforms for q-ary polar codes
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// This source is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// This file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this source distribution.
+// If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef _qpc_fwht_h_
+#define _qpc_fwht_h_
+
+#include "np_qpc.h"
+
+#if QPC_LOG2Q==7
+#define qpc_fwht(a,b) qpc_fwht128(a,b)
+#endif
+#if QPC_LOG2Q==6
+#define qpc_fwht(a,b) qpc_fwht64(a,b)
+#endif
+#if QPC_LOG2Q==5
+#define qpc_fwht(a,b) qpc_fwht32(a,b)
+#endif
+#if QPC_LOG2Q==4
+#define qpc_fwht(a,b) qpc_fwht16(a,b)
+#endif
+// Note that it makes no sense to use fast convolutions
+// for transforms that are less than 16 symbols in size.
+// For such cases direct convolutions are faster.
+#if QPC_LOG2Q==3
+#define qpc_fwht(a,b) qpc_fwht8(a,b)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ float* qpc_fwht8(float* y, float* x);
+ float* qpc_fwht16(float* y, float* x);
+ float* qpc_fwht32(float* y, float* x);
+ float* qpc_fwht64(float* y, float* x);
+ float* qpc_fwht128(float* y, float* x);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _qpc_fwht_h_
diff --git a/lib/superfox/qpc/qpc_main.cpp b/lib/superfox/qpc/qpc_main.cpp new file mode 100755 index 00000000..4da5ed99 --- /dev/null +++ b/lib/superfox/qpc/qpc_main.cpp @@ -0,0 +1,198 @@ +
+// ------------------------------------------------------------------------------
+// qpc_main.cpp
+//
+// Test the WER performance of the QPC (127,50) Q=128 code
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
+
+#include "dbgprintf.h"
+#include "qpc_fwht.h"
+#include "np_qpc.h"
+
+// for random numbers generation and NCFSK Rayleigh channel simulation
+#include "np_rnd.h"
+void qpc_channel(float* yout, unsigned char* y, float EsNo)
+{
+ // compute channel outputs amplitudes
+
+ int k;
+
+ // generate noise samples -----------------------------------------
+ float sigman = 1.0f / sqrtf(2.0f);
+ np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman);
+
+ // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N);
+
+ // generate rayleigh distributed signal amplitudes -----------------
+ float symamps[QPC_N * 2];
+ np_normrnd_cpx(symamps, QPC_N, 0, sigman);
+
+ // dbgprintf_vector_float("symamps", symamps, QPC_N*2);
+
+ // normalize signal amps to unity ----------------------------------
+ float pwr = 0.0f;
+ float* psymamps = symamps;
+ // compute sig power
+ for (k = 0; k < QPC_N; k++) {
+ pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1];
+ psymamps += 2;
+ }
+ pwr = pwr / QPC_N;
+
+ // normalize to avg EsNo
+ float norm = sqrtf(EsNo/pwr);
+ psymamps = symamps;
+ for (k = 0; k < QPC_N; k++) {
+ psymamps[0] *= norm;
+ psymamps[1] *= norm;
+ psymamps += 2;
+ }
+ // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2);
+
+ // add signal amplitudes to noise -----------------------------------
+ float *pyout = yout;
+ psymamps= symamps;
+ for (k = 0; k < QPC_N; k++) {
+ pyout[y[k]<<1] += psymamps[0];
+ pyout[(y[k]<<1)+1] += psymamps[1];
+ pyout += (QPC_Q*2);
+ psymamps += 2;
+ }
+
+ // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N);
+
+ return;
+}
+void qpc_likelihoods(float* py, float* yout, float EsNo, float No)
+{
+ // compute symbols likelihoods
+ // (rayleigh channel)
+
+ int k, j;
+
+ float norm = EsNo / (EsNo + 1) / No;
+
+ // compute likelihoods from energies ----------------------------
+ float* pybase;
+ float* ppyout = yout;
+ float normpwr;
+ float normpwrmax;
+ float pynorm;
+
+ for (k = 0; k < QPC_N; k++) {
+
+ // compute loglikelihoods and largest one from energies
+ pybase = py + k * QPC_Q;
+ normpwrmax = 0.0f;
+ for (j = 0; j < QPC_Q; j++) {
+ normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]);
+ pybase[j] = normpwr;
+ if (normpwr > normpwrmax)
+ normpwrmax = normpwr;
+ ppyout += 2;
+ }
+ // subtract largest exponent
+ pynorm = 0.0f;
+ for (j = 0; j < QPC_Q; j++) {
+ pybase[j] = expf(pybase[j] - normpwrmax);
+ pynorm += pybase[j];
+ }
+ // normalize to probabilities
+ pynorm = 1.0f / pynorm;
+ for (j = 0; j < QPC_Q; j++)
+ pybase[j] = pybase[j] * pynorm;
+
+ }
+
+ return;
+}
+
+int main()
+{
+ int k;
+
+ int NT = 20000; // number of transmissions to simultate
+ float EbNodB = 3.7f; // Eb/No to simulate
+
+
+ int kc = qpccode.k;
+ int np = qpccode.np;
+ float Rc = 1.0f * kc / np;
+ float Tm = 10.0f; // message duration
+ float Rb = 1.0f / Tm * (QPC_K - 2) * QPC_LOG2Q; // Bit rate assuming two symbols for CRC
+
+ float EsNodB = EbNodB + 10.0f * log10f(Rc * QPC_LOG2Q);
+
+ static unsigned char xin[QPC_K]; // input information symbols
+ static unsigned char xdec[QPC_K]; // decoded information symbols
+ static unsigned char y[QPC_N]; // encoded codeword
+ static unsigned char ydec[QPC_N]; // decoded codeword
+
+ static float yout[QPC_N * QPC_Q * 2]; // channel complex amplitutes output
+ static float py[QPC_N * QPC_Q]; // channel output probabilities
+
+ float EsNo = powf(10.0f, EsNodB / 10.0f);
+ float No = 1.0f;
+
+ //JHT static float we;
+ static float wer;
+
+ int kk;
+
+ printf("QPC Word Error Rate Test\n");
+ printf("Polar Code (%d,%d) Q=%d for the Rayleigh channel\n", qpccode.np, qpccode.k, qpccode.q);
+ printf("Eb/No = %.1f dB\n", EbNodB);
+ printf("Es/No = %.1f dB\n", EsNodB);
+ printf("Tmsg = %.1f s\n", Tm);
+ printf("Bit Rate = %.1f bit/s\n", Rb);
+ printf("SNR(2500) = %.1f dB\n\n", EbNodB + 10.0f * log10f(Rb/ 2500));
+
+
+ for (k = 0; k < NT; k++) {
+
+ np_unidrnd_uc(xin, QPC_K, QPC_Q); // generate random information symbols
+
+ qpc_encode(y, xin); // encode
+
+ // compute channel outputs and probabilities
+
+ // Note that if the code is punctured (i.e. N=127)
+ // the first codeword symbol must not be transmitted over the channel
+ // Here, in order to avoid useless copies,
+ // the vector of likelihoods py continues to be a QPC_N*QPC_Q vector of floats.
+ // The first received symbol likelihoods should start always at offset QPC_Q.
+ // The first QPC_Q positions of py will be ignored (and set) by the decoder.
+ qpc_channel(yout, y, EsNo);
+
+ // The decoder can't estimate the EsNo easily
+ // so we assume that in any case it is 5 dB
+ float EsNoDec = 3.16;
+ qpc_likelihoods(py, yout, EsNoDec, No);
+
+ qpc_decode(xdec, ydec, py); // decode
+
+ // count words in errors
+ for (kk = 0; kk < QPC_K; kk++)
+ if (xin[kk] ^ xdec[kk]) {
+ wer += 1;
+ break;
+ }
+
+ // show the decoder performance every 200 codewords transmissions
+ if ((k % 200) == 0 && k>0) {
+ printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k);
+ fflush(stdout);
+ }
+
+ }
+ // show the final result
+ printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k);
+ printf("\nAll done.\n");
+ return 0;
+}
diff --git a/lib/superfox/qpc/qpc_mod.f90 b/lib/superfox/qpc/qpc_mod.f90 new file mode 100755 index 00000000..069c77b1 --- /dev/null +++ b/lib/superfox/qpc/qpc_mod.f90 @@ -0,0 +1,38 @@ +module qpc_mod
+ interface
+ integer(c_int32_t) function nhash2 (xin, length, initval) bind(C, &
+ name="nhash2")
+ use iso_c_binding, only: c_signed_char, c_int64_t, c_int32_t
+ integer(c_int64_t), intent(in), value :: length
+ integer(c_signed_char), intent(in) :: xin(length)
+ integer(c_int32_t), intent(in), value :: initval
+ end function nhash2
+ end interface
+
+ interface
+ subroutine qpc_encode(y, xin) bind(C,name="qpc_encode")
+ use iso_c_binding, only: c_ptr, c_signed_char
+ integer(c_signed_char), intent(out) :: y(127)
+ integer(c_signed_char), intent(in) :: xin(50)
+ end subroutine qpc_encode
+ end interface
+
+ interface
+ subroutine qpc_channel(yout, y, EsNo) bind(C,name="qpc_channel")
+ use iso_c_binding, only: c_float_complex, c_float, c_signed_char
+ complex(c_float_complex), intent(out) :: yout(128,128)
+ integer(c_signed_char), intent(out) :: y(127)
+ real(c_float), intent(in), value :: EsNo
+ end subroutine qpc_channel
+ end interface
+
+ interface
+ subroutine qpc_decode(xdec, ydec, py) bind(C,name="qpc_decode")
+ use iso_c_binding, only: c_float, c_signed_char
+ real(c_float), intent(in) :: py(128,128)
+ integer(c_signed_char), intent(out) :: ydec(127)
+ integer(c_signed_char), intent(out) :: xdec(50)
+ end subroutine qpc_decode
+ end interface
+
+end module qpc_mod
diff --git a/lib/superfox/qpc/qpc_n127k50q128.c b/lib/superfox/qpc/qpc_n127k50q128.c new file mode 100755 index 00000000..c57bcd2b --- /dev/null +++ b/lib/superfox/qpc/qpc_n127k50q128.c @@ -0,0 +1,60 @@ +// ------------------------------------------------------------------------------
+// qpc_n127k50q128.c
+//
+// Defines the parameters of the q-ary polar code (127,50) Q=128
+// for WSJT-X
+// ------------------------------------------------------------------------------
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+//
+// WARNING:
+// This source is NOT free software and it is licensed only for use with WSJT-X.
+// No derived work is authorized to use this code without the written
+// permission of his author (Nico Palermo / IV3NWV) who owns all the rights
+// of this IP (intellectual property).
+//
+// This file is distributed ONLY for the purpose of documenting and making of
+// public domain the encoding scheme used in WSJT-X so that the transmitted
+// messages can be decoded by anybody.
+// Anyway this does not imply that one could use the following tables in a
+// derived work without an explicit and written authorization from his author.
+// Any unauthorized use, as for any intellectual property, is simply
+// illegal.
+// -------------------------------------------------------------------------------
+#include "np_qpc.h"
+qpccode_ds qpccode = {
+ 128, //n
+ 127, //np
+ 50, //k
+ 128, //q
+{
+ 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 16, 32, 17, 18, 64, 20,
+ 33, 34, 24, 7, 11, 36, 13, 19, 14, 65, 40, 21, 66, 22, 35, 68,
+ 25, 48, 37, 26, 72, 15, 38, 28, 41, 67, 23, 80, 42, 69, 49, 96,
+ 44, 27, 70, 50, 73, 39, 29, 52, 74, 30, 56, 81, 76, 43, 82, 84,
+ 97, 45, 71, 88, 98, 46, 100, 51, 104, 53, 75, 112, 54, 57, 99, 119,
+ 92, 77, 58, 117, 59, 83, 106, 31, 85, 108, 115, 116, 122, 125, 124, 91,
+ 61, 90, 89, 111, 78, 93, 94, 126, 86, 107, 110, 118, 121, 62, 120, 87,
+105, 55, 114, 60, 127, 63, 103, 101, 123, 95, 102, 47, 109, 79, 113, 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, 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, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 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, 0, 0, 0, 0, 0
+}
+};
diff --git a/lib/superfox/qpc/qpc_subs.c b/lib/superfox/qpc/qpc_subs.c new file mode 100755 index 00000000..cc6625e8 --- /dev/null +++ b/lib/superfox/qpc/qpc_subs.c @@ -0,0 +1,115 @@ +// ------------------------------------------------------------------------------
+// qpc_test.cpp
+//
+// Test the WER performance of the QPC (127,50) Q=128 code
+//
+// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy
+// ------------------------------------------------------------------------------
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
+#include <time.h>
+
+#include "dbgprintf.h"
+#include "qpc_fwht.h"
+#include "np_qpc.h"
+
+#include "nhash2.h"
+
+// for random numbers generation and NCFSK Rayleigh channel simulation
+#include "np_rnd.h"
+void qpc_channel(float* yout, unsigned char* y, float EsNo)
+{
+ // compute channel outputs amplitudes
+
+ int k;
+
+ // generate noise samples -----------------------------------------
+ float sigman = 1.0f / sqrtf(2.0f);
+ np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman);
+
+ // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N);
+
+ // generate rayleigh distributed signal amplitudes -----------------
+ float symamps[QPC_N * 2];
+ np_normrnd_cpx(symamps, QPC_N, 0, sigman);
+
+ // dbgprintf_vector_float("symamps", symamps, QPC_N*2);
+
+ // normalize signal amps to unity ----------------------------------
+ float pwr = 0.0f;
+ float* psymamps = symamps;
+ // compute sig power
+ for (k = 0; k < QPC_N; k++) {
+ pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1];
+ psymamps += 2;
+ }
+ pwr = pwr / QPC_N;
+
+ // normalize to avg EsNo
+ float norm = sqrtf(EsNo/pwr);
+ psymamps = symamps;
+ for (k = 0; k < QPC_N; k++) {
+ psymamps[0] *= norm;
+ psymamps[1] *= norm;
+ psymamps += 2;
+ }
+ // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2);
+
+ // add signal amplitudes to noise -----------------------------------
+ float *pyout = yout;
+ psymamps= symamps;
+ for (k = 0; k < QPC_N; k++) {
+ pyout[y[k]<<1] += psymamps[0];
+ pyout[(y[k]<<1)+1] += psymamps[1];
+ pyout += (QPC_Q*2);
+ psymamps += 2;
+ }
+
+ // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N);
+
+ return;
+}
+void qpc_likelihoods(float* py, float* yout, float EsNo, float No)
+{
+ // compute symbols likelihoods
+ // (rayleigh channel)
+
+ int k, j;
+
+ float norm = EsNo / (EsNo + 1) / No;
+
+ // compute likelihoods from energies ----------------------------
+ float* pybase;
+ float* ppyout = yout;
+ float normpwr;
+ float normpwrmax;
+ float pynorm;
+
+ for (k = 0; k < QPC_N; k++) {
+
+ // compute loglikelihoods and largest one from energies
+ pybase = py + k * QPC_Q;
+ normpwrmax = 0.0f;
+ for (j = 0; j < QPC_Q; j++) {
+ normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]);
+ pybase[j] = normpwr;
+ if (normpwr > normpwrmax)
+ normpwrmax = normpwr;
+ ppyout += 2;
+ }
+ // subtract largest exponent
+ pynorm = 0.0f;
+ for (j = 0; j < QPC_Q; j++) {
+ pybase[j] = expf(pybase[j] - normpwrmax);
+ pynorm += pybase[j];
+ }
+ // normalize to probabilities
+ pynorm = 1.0f / pynorm;
+ for (j = 0; j < QPC_Q; j++)
+ pybase[j] = pybase[j] * pynorm;
+ }
+
+ return;
+}
diff --git a/lib/superfox/qpc_decode2.f90 b/lib/superfox/qpc_decode2.f90 new file mode 100755 index 00000000..a795ff6e --- /dev/null +++ b/lib/superfox/qpc_decode2.f90 @@ -0,0 +1,150 @@ +subroutine qpc_decode2(c0,fsync,ftol,xdec,ndepth,dth,damp,crc_ok, &
+ snrsync,fbest,tbest,snr)
+
+ use qpc_mod
+
+ parameter(NMAX=15*12000,NFT=365,NZ=100)
+ complex c0(NMAX) !Signal as received
+ complex c(NMAX) !Signal as received
+ real py(0:127,0:127) !Probabilities for received synbol values
+ real py0(0:127,0:127) !Probabilities for strong signal
+ real pyd(0:127,0:127) !Dithered values for py
+ real s2(0:127,0:151) !Symbol spectra, including sync
+ real s3(0:127,0:127) !Synchronized symbol spectra
+ real No
+ integer crc_chk,crc_sent
+ integer*8 n47
+ integer idf(NZ),idt(NZ)
+ integer nseed(33)
+ integer*1 xdec(0:49) !Decoded message
+ integer*1 ydec(0:127) !Decoded symbols
+ logical crc_ok
+ integer maxdither(8)
+ integer isync(24) !Symbol numbers for sync tones
+ data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80,83, &
+ 84,86,89/
+ data n47/47/,maxdither/20,50,100,200,500,1000,2000,5000/
+ data nseed/ &
+ 321278106, -658879006, 1239150429, -941466001, -698554454, &
+ 1136210962, 1633585627, 1261915021, -1134191465, -487888229, &
+ 2131958895, -1429290834, -1802468092, 1801346659, 1966248904, &
+ 402671397, -1961400750, -1567227835, 1895670987, -286583128, &
+ -595933665, -1699285543, 1518291336, 1338407128, 838354404, &
+ -2081343776, -1449416716, 1236537391, -133197638, 337355509, &
+ -460640480, 1592689606, 0/
+
+ data idf/0, 0, -1, 0, -1, 1, 0, -1, 1, -2, 0, -1, 1, -2, 2, &
+ 0, -1, 1, -2, 2, -3, 0, -1, 1, -2, 2, -3, 3, 0, -1, &
+ 1, -2, 2, -3, 3, -4, 0, -1, 1, -2, 2, -3, 3, -4, 4, &
+ 0, -1, 1, -2, 2, -3, 3, -4, 4, -5, -1, 1, -2, 2, -3, &
+ 3, -4, 4, -5, 1, -2, 2, -3, 3, -4, 4, -5, -2, 2, -3, &
+ 3, -4, 4, -5, 2, -3, 3, -4, 4, -5, -3, 3, -4, 4, -5, &
+ 3, -4, 4, -5, -4, 4, -5, 4, -5, -5/
+ data idt/0 , -1, 0, 1, -1, 0, -2, 1, -1, 0, 2, -2, 1, -1, 0, &
+ -3, 2, -2, 1, -1, 0, 3, -3, 2, -2, 1, -1, 0, -4, 3, &
+ -3, 2, -2, 1, -1, 0, 4, -4, 3, -3, 2, -2, 1, -1, 0, &
+ -5, 4, -4, 3, -3, 2, -2, 1, -1, 0, -5, 4, -4, 3, -3, &
+ 2, -2, 1, -1, -5, 4, -4, 3, -3, 2, -2, 1, -5, 4, -4, &
+ 3, -3, 2, -2, -5, 4, -4, 3, -3, 2, -5, 4, -4, 3, -3, &
+ -5, 4, -4, 3, -5, 4, -4, -5, 4, -5/
+
+
+ fsample=12000.0
+ baud=12000.0/1024.0
+ nstype=1
+ n47=47
+ mask21=2**21 - 1
+ crc_ok=.false.
+
+ call qpc_sync(c0,fsample,isync,fsync,ftol,f2,t2,snrsync)
+ f00=1500.0 + f2
+ t00=t2
+ fbest=f00
+ tbest=t00
+ maxd=1
+ if(ndepth.gt.0) maxd=maxdither(ndepth)
+ maxft=NZ
+ if(snrsync.lt.4.0 .or. ndepth.le.0) maxft=1
+ do idith=1,maxft
+ if(idith.ge.2) maxd=1
+ deltaf=idf(idith)*0.5
+ deltat=idt(idith)*8.0/1024.0
+ f=f00+deltaf
+ t=t00+deltat
+ fshift=1500.0 - (f+baud) !Shift frequencies down by f + 1 bin
+ call twkfreq2(c0,c,NMAX,fsample,fshift)
+ a=1.0
+ b=0.0
+ do kk=1,4
+ if(kk.eq.2) b=0.4
+ if(kk.eq.3) b=0.5
+ if(kk.eq.4) b=0.6
+ call sfox_demod(c,1500.0,t,isync,s2,s3) !Compute s2 and s3
+
+ if(b.gt.0.0) then
+ do j=0,127
+ call smo121a(s3(:,j),128,a,b)
+ enddo
+ endif
+ call pctile(s3,128*128,50,base3)
+ s3=s3/base3
+
+ EsNoDec=3.16
+ No=1.
+ py0=s3
+ call qpc_likelihoods2(py,s3,EsNoDec,No) !For weak signals
+
+ call random_seed(put=nseed)
+ do kkk=1,maxd
+ if(kkk.eq.1) then
+ pyd=py0
+ else
+ pyd=0.
+ if(kkk.gt.2) then
+ call random_number(pyd)
+ pyd=2.0*(pyd-0.5)
+ endif
+ where(py.gt.dth) pyd=0. !Don't perturb large likelihoods
+ pyd=py*(1.0 + damp*pyd) !Compute dithered likelihood
+ endif
+ do j=0,127
+ ss=sum(pyd(:,j))
+ if(ss.gt.0.0) then
+ pyd(:,j)=pyd(:,j)/ss
+ else
+ pyd(:,j)=0.0
+ endif
+ enddo
+
+ call qpc_decode(xdec,ydec,pyd)
+ xdec=xdec(49:0:-1)
+ crc_chk=iand(nhash2(xdec,n47,571),mask21) !Compute crc_chk
+ crc_sent=128*128*xdec(47) + 128*xdec(48) + xdec(49)
+ crc_ok=crc_chk.eq.crc_sent
+
+ if(crc_ok) then
+ call qpc_snr(s3,ydec,snr)
+ if(snr.lt.-16.5) crc_ok=.false.
+! write(61,3061) idith,kk,kkk,idf(idith),idt(idith),a,b
+!3061 format(5i5,2f8.3)
+ return
+ endif
+ enddo !kk: dither of smoothing weights
+ enddo !kkk: dither of probabilities
+ enddo !idith: dither of frequency and time
+ return
+end subroutine qpc_decode2
+
+subroutine smo121a(x,nz,a,b)
+
+ real x(nz)
+ fac=1.0/(a+2*b)
+ x0=x(1)
+ do i=2,nz-1
+ x1=x(i)
+ x(i)=fac*(a*x(i) + b*(x0+x(i+1)))
+ x0=x1
+ enddo
+
+ return
+end subroutine smo121a
diff --git a/lib/superfox/qpc_likelihoods2.f90 b/lib/superfox/qpc_likelihoods2.f90 new file mode 100755 index 00000000..e1393594 --- /dev/null +++ b/lib/superfox/qpc_likelihoods2.f90 @@ -0,0 +1,28 @@ +subroutine qpc_likelihoods2(py,s3,EsNo,No)
+
+ integer QQ,QN
+ parameter(QQ=128,QN=128)
+ real py(0:QQ-1,0:QN-1)
+ real s3(0:QQ-1,0:QN-1)
+ real No,norm,normpwr,normpwrmax
+
+ norm=(EsNo/(EsNo+1.0))/No
+
+! Compute likelihoods for symbol values, from the symbol power spectra
+ do k=0,QN-1
+ normpwrmax=0.
+ do j=0,QQ-1
+ normpwr=norm*s3(j,k)
+ py(j,k)=normpwr
+ normpwrmax=max(normpwr,normpwrmax)
+ enddo
+ pynorm=0.
+ do j=0,QQ-1
+ py(j,k)=exp(py(j,k)-normpwrmax)
+ pynorm=pynorm + py(j,k)
+ enddo
+ py(0:QQ-1,k)=py(0:QQ-1,k)/pynorm !Normalize to probabilities
+ enddo
+
+ return
+end subroutine qpc_likelihoods2
diff --git a/lib/superfox/qpc_snr.f90 b/lib/superfox/qpc_snr.f90 new file mode 100755 index 00000000..457d2504 --- /dev/null +++ b/lib/superfox/qpc_snr.f90 @@ -0,0 +1,17 @@ +subroutine qpc_snr(s3,y,snr)
+
+ use qpc_mod
+! real s2(0:NQ-1,0:151) !Symbol spectra, including sync
+ real s3(0:127,0:127) !Synchronized symbol spectra
+ integer*1 y(0:127) !Encoded symbols
+! integer isync(24)
+
+ p=0.
+ do j=1,127
+ i=y(j)
+ p=p + s3(i,j)
+ enddo
+ snr=db(p/127.0) - db(127.0) - 4.0
+
+ return
+end subroutine qpc_snr
diff --git a/lib/superfox/qpc_sync.f90 b/lib/superfox/qpc_sync.f90 new file mode 100755 index 00000000..03c13d19 --- /dev/null +++ b/lib/superfox/qpc_sync.f90 @@ -0,0 +1,113 @@ +subroutine qpc_sync(crcvd0,fsample,isync,fsync,ftol,f2,t2,snrsync)
+
+ parameter(N9SEC=9*12000,NMAX=15*12000,NDOWN=16,NZ=N9SEC/NDOWN)
+ complex crcvd0(NMAX) !Signal as received
+ complex c0(0:N9SEC-1) !For long FFT
+ complex c1(0:NZ-1)
+ complex c1sum(0:NZ-1)
+ complex z
+ real s(N9SEC/4)
+ real p(-1125:1125)
+ integer ipk(1)
+ integer isync(24)
+
+ baud=12000.0/1024.0
+ df2=fsample/N9SEC
+ fac=1.0/N9SEC
+ c0=fac*crcvd0(1:N9SEC)
+ call four2a(c0,N9SEC,1,-1,1) !Forward c2c FFT
+ iz=N9SEC/4
+ do i=1,iz
+ s(i)=real(c0(i))**2 + aimag(c0(i))**2
+ enddo
+
+ do i=1,4 !Smooth the spectrum a bit
+ call smo121(s,iz)
+ enddo
+
+ ia=nint((fsync-ftol)/df2)
+ ib=nint((fsync+ftol)/df2)
+
+ if (ia .lt. 1) ia=1; ! Avoid a potential bounds error
+ if (ib .ge. 27000) ib=27000; ! Avoid a potential bounds error
+
+ ipk=maxloc(s(ia:ib))
+ i0=ipk(1) + ia - 1
+ f2=df2*i0-750.0 ! f2 is the offset from nominal 750 Hz.
+ ia=nint(i0-baud/df2)
+ ib=nint(i0+baud/df2)
+
+ if (ia .lt. 1) ia=1; ! Avoid a potential bounds error
+ if (ib .ge. 27000) ib=27000; ! Avoid a potential bounds error
+
+ s1=0.0
+ s0=0.0
+ do i=ia,ib
+ s0=s0+s(i)
+ s1=s1+(i-i0)*s(i)
+ enddo
+ delta=s1/s0
+ i0=nint(i0+delta)
+ f2=i0*df2-750.0
+
+ c1=0.
+ ia=nint(i0-baud/df2)
+ ib=nint(i0+baud/df2)
+
+ if (ia .lt. 0) ia=0; ! Avoid a potential bounds error
+ if (ib .ge. N9SEC-1) ib=N9SEC-1; ! Avoid a potential bounds error
+
+ do i=ia,ib
+ j=i-i0
+ if(j.ge.0) c1(j)=c0(i)
+ if(j.lt.0) c1(j+NZ)=c0(i)
+ enddo
+ call four2a(c1,NZ,1,1,1) !Reverse c2c FFT: back to time domain
+
+ c1sum(0)=c1(0)
+ do i=1,NZ-1
+ c1sum(i)=c1sum(i-1) + c1(i)
+ enddo
+
+ nspsd=1024/NDOWN
+ dt=NDOWN/12000.0
+ lagmax=1.5/dt
+ i0=nint(0.5*fsample/NDOWN) !Nominal start time is 0.5 s
+ pmax=0.
+ lagpk=0
+ do lag=-lagmax,lagmax
+ sp=0.
+ do j=1,24
+ i1=i0 + (isync(j)-1)*nspsd + lag
+ i2=i1 + nspsd
+ if(i1.lt.0 .or. i1.gt.NZ-1) cycle
+ if(i2.lt.0 .or. i2.gt.NZ-1) cycle
+ z=c1sum(i2)-c1sum(i1)
+ sp=sp + real(z)**2 + aimag(z)**2
+ enddo
+ if(sp.gt.pmax) then
+ pmax=sp
+ lagpk=lag
+ endif
+ p(lag)=sp
+ enddo
+
+ t2=lagpk*dt
+ snrsync=0.
+ sp=0.
+ sq=0.
+ nsum=0
+ tsym=1024/12000.0
+ do lag=-lagmax,lagmax
+ t=(lag-lagpk)*dt
+ if(abs(t).lt.tsym) cycle
+ nsum=nsum+1
+ sp=sp + p(lag)
+ sq=sq + p(lag)*p(lag)
+ enddo
+ ave=sp/nsum
+ rms=sqrt(sq/nsum-ave*ave)
+ snrsync=(pmax-ave)/rms
+
+ return
+end subroutine qpc_sync
diff --git a/lib/superfox/ran1.f90 b/lib/superfox/ran1.f90 new file mode 100755 index 00000000..d0b35b74 --- /dev/null +++ b/lib/superfox/ran1.f90 @@ -0,0 +1,28 @@ +FUNCTION ran1(idum)
+ INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
+ REAL ran1,AM,EPS,RNMX
+ PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836, &
+ NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
+ INTEGER j,k,iv(NTAB),iy
+ SAVE iv,iy
+ DATA iv /NTAB*0/, iy /0/
+ if (idum.le.0.or.iy.eq.0) then
+ idum=max(-idum,1)
+ do j=NTAB+8,1,-1
+ k=idum/IQ
+ idum=IA*(idum-k*IQ)-IR*k
+ if (idum.lt.0) idum=idum+IM
+ if (j.le.NTAB) iv(j)=idum
+ enddo
+ iy=iv(1)
+ endif
+ k=idum/IQ
+ idum=IA*(idum-k*IQ)-IR*k
+ if (idum.lt.0) idum=idum+IM
+ j=1+iy/NDIV
+ iy=iv(j)
+ iv(j)=idum
+ ran1=min(AM*iy,RNMX)
+
+ return
+END FUNCTION ran1
diff --git a/lib/superfox/sfox_ana.f90 b/lib/superfox/sfox_ana.f90 new file mode 100755 index 00000000..5983d31b --- /dev/null +++ b/lib/superfox/sfox_ana.f90 @@ -0,0 +1,17 @@ +subroutine sfox_ana(dd,npts,c0,npts2)
+
+ real dd(npts) !Raw data at 12000 Hz
+ complex c0(0:npts2-1) !Complex data at 12000 Hz
+ save
+
+ nfft1=npts
+ nfft2=nfft1
+ fac=2.0/(32767.0*nfft1)
+ c0(0:npts-1)=fac*dd(1:npts)
+ call four2a(c0,nfft1,1,-1,1) !Forward c2c FFT
+ c0(nfft2/2+1:nfft2-1)=0. !Remove negative frequencies
+ c0(0)=0.5*c0(0) !Scale the DC term to 1/2
+ call four2a(c0,nfft2,1,1,1) !Inverse c2c FFT; c0 is analytic sig
+
+ return
+end subroutine sfox_ana
diff --git a/lib/superfox/sfox_assemble.f90 b/lib/superfox/sfox_assemble.f90 new file mode 100755 index 00000000..cf1810d7 --- /dev/null +++ b/lib/superfox/sfox_assemble.f90 @@ -0,0 +1,92 @@ +subroutine sfox_assemble(ntype,k,msg,mycall0,mygrid0,line)
+
+! In subsequent calls, assemble all necessary information for a SuperFox
+! transmission.
+
+ character*120 line
+ character*26 msg
+ character*26 msg0,msg1,msg2(5),msg3(5)
+ character*4 rpt2(5)
+ character*6 hiscall(10)
+ character*13 mycall0,mycall
+ character*4 mygrid0,mygrid
+ integer ntype !Message type: 0 Free Text
+ ! 1 CQ MyCall MyGrid
+ ! 2 Call_1 MyCall RR73
+ ! 3 Call_1 MyCall rpt
+ integer nmsg(0:3) !Number of messages of type ntype
+ data nmsg/0,0,0,0/,nbits/0/,ntx/0/,nb_mycall/0/
+ save
+
+ if(mycall0(1:1).ne.' ') mycall=mycall0
+ if(mygrid0(1:1).ne.' ') mygrid=mygrid0
+ if(ntype.ge.1) nb_mycall=28 !### Allow for nonstandard MyCall ###
+ if(sum(nmsg).eq.0) then
+ hiscall=' '
+ rpt2=' '
+ endif
+
+ if(k.le.10) then
+ if(ntype.eq.0) then
+ if(nbits+nb_mycall.le.191) then !Enough room for a free text message?
+ nmsg(ntype)=nmsg(ntype)+1
+ nbits=nbits+142
+ msg0=msg
+ endif
+ else if(ntype.eq.1) then
+ if(nbits+nb_mycall.le.318) then !Enough room for a CQ ?
+ nmsg(ntype)=nmsg(ntype)+1
+ nbits=nbits+15
+ msg1=msg
+ endif
+ else if(ntype.eq.2) then
+ if(nbits+nb_mycall.le.305) then !Enough room for a RR73 message?
+ nmsg(ntype)=nmsg(ntype)+1
+ nbits=nbits+28
+ j=nmsg(ntype)
+ msg2(j)=msg
+ i1=index(msg,' ')
+ hiscall(j+5)=msg(1:i1-1)
+ endif
+ else if(ntype.eq.3) then
+ if(nbits+nb_mycall.le.300) then !Enough room for a message with report?
+ nmsg(ntype)=nmsg(ntype)+1
+ nbits=nbits+33
+ j=nmsg(ntype)
+ msg3(j)=msg
+ i1=index(msg,' ')
+ hiscall(j)=msg(1:i1-1)
+ i1=max(index(msg,'-'),index(msg,'+'))
+ rpt2(j)=msg(i1:i1+3)
+ endif
+ endif
+ return
+ endif
+
+ if(k.ge.11) then
+! All pieces are now available. Put them into a command line for external
+! program sfox_tx.
+ ntx=ntx+1 !Transmission number
+ nbits=nbits+nb_mycall !Add bits for MyCall
+
+ if(nmsg(1).ge.1) then
+ line=msg1
+ else
+ line=trim(mycall)
+ do i=1,nmsg(3)
+ line=trim(line)//' '//trim(hiscall(i))//' '//rpt2(i)
+ enddo
+ do i=1,nmsg(2)
+ line=trim(line)//' '//trim(hiscall(i+5))
+ enddo
+ endif
+
+ nmsg=0
+ nbits=0
+ nb_mycall=0
+ hiscall=' '
+ rpt2=' '
+ endif
+
+ return
+end subroutine sfox_assemble
diff --git a/lib/superfox/sfox_demod.f90 b/lib/superfox/sfox_demod.f90 new file mode 100755 index 00000000..568d6786 --- /dev/null +++ b/lib/superfox/sfox_demod.f90 @@ -0,0 +1,79 @@ +subroutine sfox_demod(crcvd,f,t,isync,s2,s3)
+
+ use sfox_mod
+ complex crcvd(NMAX) !Signal as received
+ complex c(0:NSPS-1) !Work array, one symbol long
+ real s2(0:NQ-1,0:151) !Symbol spectra, including sync
+ real s3(0:NQ-1,0:NN) !Synchronized symbol spectra
+ integer isync(24)
+ integer ipk(1)
+ integer hist1(0:NQ-1),hist2(0:NQ-1)
+
+ j0=nint(12000.0*(t+0.5))
+ df=12000.0/NSPS
+ i0=nint(f/df)-NQ/2
+ k2=0
+ s2(:,0)=0. !The punctured symbol
+ s3(:,0)=0. !The punctured symbol
+
+ do n=1,NDS !Loop over all symbols
+ jb=n*NSPS + j0
+ ja=jb-NSPS+1
+ k2=k2+1
+ if(ja.lt.1 .or. jb.gt.NMAX) cycle
+ c=crcvd(ja:jb)
+ call four2a(c,NSPS,1,-1,1) !Compute symbol spectrum
+ do i=0,NQ-1
+ s2(i,k2)=real(c(i0+i))**2 + aimag(c(i0+i))**2
+ enddo
+ enddo
+
+
+ call pctile(s2,NQ*151,50,base2)
+ s2=s2/base2
+
+ hist1=0
+ hist2=0
+ do j=0,151
+ ipk=maxloc(s2(1:NQ-1,j)) !Find the spectral peak
+ i=ipk(1)-1
+ hist1(i)=hist1(i)+1
+ enddo
+
+ hist1(0)=0 !Don't treat sync tone as a birdie
+ do i=0,123
+ hist2(i)=sum(hist1(i:i+3))
+ enddo
+
+ ipk=maxloc(hist1)
+ i1=ipk(1)-1
+ m1=maxval(hist1)
+ ipk=maxloc(hist2)
+ i2=ipk(1)-1
+ m2=maxval(hist2)
+ if(m1.gt.12) then
+ do i=0,127
+ if(hist1(i).gt.12) then
+ s2(i,:)=1.0
+ endif
+ enddo
+ endif
+
+ if(m2.gt.20) then
+ if(i2.ge.1) i2=i2-1
+ if(i2.gt.120) i2=120
+ s2(i2:i2+7,:)=1.0
+ endif
+
+ k3=0
+ do n=1,NDS !Copy symbol spectra from s2 into s3
+ if(any(isync(1:NS).eq.n)) cycle !Skip the sync symbols
+ k3=k3+1
+ s3(:,k3)=s2(:,n)
+ enddo
+
+ call pctile(s3,NQ*NN,50,base3)
+ s3=s3/base3
+
+ return
+end subroutine sfox_demod
diff --git a/lib/superfox/sfox_gen_gfsk.f90 b/lib/superfox/sfox_gen_gfsk.f90 new file mode 100755 index 00000000..63524eb3 --- /dev/null +++ b/lib/superfox/sfox_gen_gfsk.f90 @@ -0,0 +1,85 @@ +subroutine sfox_gen_gfsk(idat,f0,isync,itone,cdat)
+
+ parameter (NSPS=1024)
+ parameter (NDS=151)
+ parameter (NN=127) !NN = number of code symbols
+ parameter (NS=24) !NS = number of sync symbols
+ parameter (NMAX=15*12000)
+ parameter (NPTS=(NDS+2)*NSPS) !# of samples in waveform at 12000 samples/sec
+ parameter (BT=8) !GFSK time-bandwidth product
+
+ complex cdat(NMAX)
+ integer idat(NN)
+ integer isync(NS)
+ integer itone(NDS)
+ real*8 dt,twopi,phi,dphi_peak
+ real*8 dphi(0:NPTS-1)
+ real pulse(3*NSPS)
+ logical first/.true./
+
+ save first,twopi,dt,hmod,dphi_peak,pulse
+
+ if(first) then
+ twopi=8.d0*atan(1.0)
+ fsample=12000.0
+ dt=1.0/fsample
+ hmod=1.0
+ dphi_peak=twopi*hmod/real(NSPS)
+ do i=1,3*NSPS
+ tt=(i-1.5*NSPS)/real(NSPS)
+ pulse(i)=gfsk_pulse(BT,tt)
+ enddo
+ first=.false.
+ endif
+ wave=0.
+
+! Create the itone sequence: data symbols and interspersed sync symbols
+ j=1
+ k=0
+ do i=1,NDS
+ if(j.le.NS .and. i.eq.isync(j)) then
+ if(j.lt.NS) j=j+1 !Index for next sync symbol
+ itone(i)=0 !Insert sync symbol at tone 0
+ else
+ k=k+1
+ itone(i)=idat(k) + 1 !Symbol value 0 is transmitted at tone 1, etc.
+ endif
+ enddo
+
+! Generate the SuperFox waveform.
+
+ dphi=0.d0
+ do j=1,NDS
+ ib=(j-1)*NSPS
+ ie=ib+3*NSPS-1
+ dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j)
+ enddo
+ dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS)
+ dphi(NDS*NSPS:(NDS+2)*NSPS-1)=dphi(NDS*NSPS:(NDS+2)*NSPS-1)+dphi_peak*itone(NDS)*pulse(1:2*NSPS)
+
+ phi=0.d0
+ dphi=dphi+twopi*f0*dt
+ k=0
+ do j=1,NSPS*(NDS+2)-1
+ k=k+1
+ cdat(k)=cmplx(cos(phi),sin(phi))
+ phi=phi+dphi(j)
+ enddo
+
+! Add raised cosine ramps at the beginning and end of the waveform.
+! Since the modulator expects an integral number of symbols, dummy
+! symbols are added to the beginning and end of the waveform to
+! hold the ramps. All but nramp of the samples in each dummy
+! symbol will be zero.
+
+ nramp=NSPS/BT
+ cdat(1:NSPS-nramp)=cmplx(0.0,0.0)
+ cdat(NSPS-nramp+1:NSPS)=cdat(NSPS-nramp+1:NSPS) * &
+ (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ k1=(NDS+1)*NSPS+1
+ cdat(k1:k1+nramp-1)=cdat(k1:k1+nramp-1) * &
+ (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ cdat(k1+nramp:NPTS)=0.0
+
+ return
+end subroutine sfox_gen_gfsk
diff --git a/lib/superfox/sfox_mod.f90 b/lib/superfox/sfox_mod.f90 new file mode 100755 index 00000000..6c4d8390 --- /dev/null +++ b/lib/superfox/sfox_mod.f90 @@ -0,0 +1,73 @@ +module sfox_mod
+
+ parameter (NMAX=15*12000) !Samples in iwave (180,000)
+ integer MM,NQ,NN,KK,NS,NDS,NFZ,NSPS,NSYNC,NZ,NFFT1
+ real baud,tsym,bw
+
+contains
+ subroutine sfox_init(mm0,nn0,kk0,itu,fspread,delay,fsample,ns0)
+
+ character*2 itu
+ integer isps(54)
+ integer iloc(1)
+ data isps/ 896, 960, 972, 980,1000,1008,1024,1029,1050,1080, &
+ 1120,1125,1134,1152,1176,1200,1215,1225,1250,1260, &
+ 1280,1296,1323,1344,1350,1372,1400,1440,1458,1470, &
+ 1500,1512,1536,1568,1575,1600,1620,1680,1701,1715, &
+ 1728,1750,1764,1792,1800,1875,1890,1920,1944,1960, &
+ 2000,2016,2025,2048/
+
+ MM=mm0 !Bits per symbol
+ NQ=2**MM !Q, number of MFSK tones
+ NN=nn0 !Codeword length
+ KK=kk0 !Number of information symbols
+ NS=ns0 !Number of sync symbols
+ NDS=NN+NS !Total number of channel symbols
+ NFZ=3 !First zero
+
+ jsps=nint(12.8*fsample/NDS)
+ iloc=minloc(abs(isps-jsps))
+ NSPS=isps(iloc(1)) !Samples per symbol
+ NSYNC=NS*NSPS !Samples in sync waveform
+ NZ=NSPS*NDS !Samples in full Tx waveform
+ NFFT1=2*NSPS !Length of FFTs for symbol spectra
+
+ baud=fsample/NSPS
+ tsym=1.0/baud
+ bw=NQ*baud
+
+ fspread=0.0
+ delay=0.0
+ if(itu.eq.'LQ') then
+ fspread=0.5
+ delay=0.5
+ else if(itu.eq.'LM') then
+ fspread=1.5
+ delay=2.0
+ else if(itu.eq.'LD') then
+ fspread=10.0
+ delay=6.0
+ else if(itu.eq.'MQ') then
+ fspread=0.1
+ delay=0.5
+ else if(itu.eq.'MM') then
+ fspread=0.5
+ delay=1.0
+ else if(itu.eq.'MD') then
+ fspread=1.0
+ delay=2.0
+ else if(itu.eq.'HQ') then
+ fspread=0.5
+ delay=1.0
+ else if(itu.eq.'HM') then
+ fspread=10.0
+ delay=3.0
+ else if(itu.eq.'HD') then
+ fspread=30.0
+ delay=7.0
+ endif
+
+ return
+ end subroutine sfox_init
+
+end module sfox_mod
diff --git a/lib/superfox/sfox_pack.f90 b/lib/superfox/sfox_pack.f90 new file mode 100755 index 00000000..56ccf89a --- /dev/null +++ b/lib/superfox/sfox_pack.f90 @@ -0,0 +1,178 @@ +subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin)
+
+ use qpc_mod
+ use packjt
+ use packjt77
+ use julian
+ parameter (NQU1RKS=203514677)
+ integer*8 n47,n58,now
+ integer*1 xin(0:49) !Packed message as 7-bit symbols
+ logical*1 bMoreCQs,bSendMsg
+ logical text,allz
+ character*120 line !SuperFox message pieces
+ character*10 ckey
+ character*26 freeTextMsg
+ character*13 w(16)
+ character*11 c11
+ character*329 msgbits !Packed message as bits
+ character*38 c
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+
+ i0=index(line,'/')
+ i3=0 !Default to i3=0, standard message
+ nh1=0 !Number of Hound calls with RR73
+ nh2=0 !Number of Hound calls with report
+
+! Split the command line into words
+ w=' '
+ i1=1
+ do j=1,16
+ do i=i1,min(i1+12,120)
+ if(line(i:i).eq.' ') exit
+ enddo
+ i2=i-1
+ w(j)=line(i1:i2)
+ do i=i2+1,120
+ if(line(i:i).ne.' ') exit
+ enddo
+ i1=i
+ if(i1.ge.120) exit
+ enddo
+ nwords=j
+
+ do i=1,nwords
+ if(w(i)(1:1).eq.' ') then
+ nwords=i-1
+ exit
+ endif
+ enddo
+
+ do i=1,329 !Set all msgbits to '0'
+ msgbits(i:i)='0'
+ enddo
+
+ now=itime8()/30
+ now=30*now
+ read(ckey(5:10),*) notp
+
+ write(msgbits(307:326),'(b20.20)') notp !Insert the digital signature
+
+ if(w(1)(1:3).eq.'CQ ') then
+ i3=3
+ c11=w(2)(1:11)
+ n58=0
+ do i=1,11
+ n58=n58*38 + index(c,c11(i:i)) - 1
+ enddo
+ write(msgbits(1:58),'(b58.58)') n58
+ call packgrid(w(3)(1:4),n15,text)
+ write(msgbits(59:73),'(b15.15)') n15
+ write(msgbits(327:329),'(b3.3)') i3 !Message type i3=3
+ go to 800
+ endif
+
+ call pack28(w(1),n28) !Fox call
+ write(msgbits(1:28),'(b28.28)') n28
+
+! Default report is RR73 if we're also sending a free text message.
+ if(bSendMsg) msgbits(141:160)='11111111111111111111'
+
+ j=29
+
+! Process callsigns with RR73
+ do i=2,nwords
+ if(w(i)(1:1).eq.'+' .or. w(i)(1:1).eq.'-') cycle !Skip report words
+ i1=min(i+1,nwords)
+ if(w(i1)(1:1) .eq.'+' .or. w(i1)(1:1).eq.'-') cycle !Skip if i+1 is report
+ call pack28(w(i),n28)
+ write(msgbits(j:j+27),1002) n28 !Insert this call for RR73 message
+1002 format(b28.28)
+ j=j+28
+ nh1=nh1+1
+ if(nh1.ge.5) exit !At most 5 RR73 callsigns
+ enddo
+
+! Process callsigns with a report
+ j=169
+ j2=281
+ if(bSendMsg) then
+ i3=2
+ j=29 + 28*nh1
+ j2=141 + 5*nh1
+ endif
+
+ do i=2,nwords
+ i1=min(i+1,nwords)
+ if(w(i1)(1:1).eq.'+' .or. w(i1)(1:1).eq.'-') then
+ call pack28(w(i),n28)
+ write(msgbits(j:j+27),1002) n28 !Insert this call
+ read(w(i1),*) n !Valid reports are -18 to +12, plus RR73
+ if(n.lt.-18) n=-18 !... Even numbers only ...
+ if(n.gt.12) n=12
+ write(msgbits(j2:j2+4),1000) n+18
+1000 format(b5.5)
+ w(i1)=""
+ nh2=nh2+1
+! print*,'C',i3,i,j,n,w(i)
+ if( nh2.ge.4 .or. (nh1+nh2).ge.9 ) exit ! At most 4 callsigns w/reports
+ j=j+28
+ j2=j2+5
+ endif
+ enddo
+
+800 if(bSendMsg) then
+ i1=26
+ do i=1,26
+ if(freeTextMsg(i:i).ne.' ') i1=i
+ enddo
+ do i=i1+1,26
+ freeTextMsg(i:i)='.'
+ enddo
+ if(i3.eq.3) then
+ call packtext77(freeTextMsg(1:13),msgbits(74:144))
+ call packtext77(freeTextMsg(14:26),msgbits(145:215))
+ elseif(i3.eq.2) then
+ call packtext77(freeTextMsg(1:13),msgbits(161:231))
+ call packtext77(freeTextMsg(14:26),msgbits(232:302))
+ endif
+ write(msgbits(327:329),'(b3.3)') i3 !Message type i3=2
+ endif
+ if(bMoreCQs) msgbits(306:306)='1'
+
+ read(msgbits(327:329),'(b3)') i3
+ if(i3.eq.0) then
+ do i=1,9
+ i0=i*28 + 1
+ read(msgbits(i0:i0+27),'(b28)') n28
+ if(n28.eq.0) write(msgbits(i0:i0+27),'(b28.28)') NQU1RKS
+ enddo
+ else if(i3.eq.3) then
+ allz=.true.
+ do i=0,6
+ i0=i*32 + 74
+ read(msgbits(i0:i0+31),'(b32)') n32
+ if(n32.ne.0) allz=.false.
+ enddo
+ if(allz) then
+ do i=0,6
+ i0=i*32 + 74
+ write(msgbits(i0:i0+31),'(b32.32)') NQU1RKS
+ enddo
+ endif
+ endif
+
+ read(msgbits,1004) xin(0:46)
+1004 format(47b7)
+
+ mask21=2**21 - 1
+ n47=47
+ ncrc21=iand(nhash2(xin,n47,571),mask21) !Compute 21-bit CRC
+ xin(47)=ncrc21/16384 !First 7 of 21 bits
+ xin(48)=iand(ncrc21/128,127) !Next 7 bits
+ xin(49)=iand(ncrc21,127) !Last 7 bits
+
+ xin=xin(49:0:-1) !Reverse the symbol order
+! NB: CRC is now in first three symbols, fox call in the last four.
+
+ return
+end subroutine sfox_pack
diff --git a/lib/superfox/sfox_prob.f90 b/lib/superfox/sfox_prob.f90 new file mode 100755 index 00000000..4a278035 --- /dev/null +++ b/lib/superfox/sfox_prob.f90 @@ -0,0 +1,55 @@ +subroutine sfox_prob(s3,rxdat,rxprob,rxdat2,rxprob2)
+
+! Demodulate the 64-bin spectra for each of 63 symbols in a frame.
+
+! Parameters
+! rxdat most reliable symbol value
+! rxdat2 second most likely symbol value
+! rxprob probability that rxdat was the transmitted value
+! rxprob2 probability that rxdat2 was the transmitted value
+
+ use sfox_mod
+ implicit real*8 (a-h,o-z)
+ real*4 s3(0:NQ-1,0:NN-1)
+ integer rxdat(0:NN-1),rxprob(0:NN-1),rxdat2(0:NN-1),rxprob2(0:NN-1)
+
+ afac=1.1
+! scale=255.999
+ scale=2047.999
+
+! Compute average spectral value
+ ave=sum(s3)/(NQ*ND)
+ i1=1 !Silence warning
+ i2=1
+
+! Compute probabilities for most reliable symbol values
+ do j=0,NN-1 !Loop over all symbols
+ s1=-1.e30
+ psum=0.
+ do i=0,NQ-1 !Loop over frequency bins
+ x=min(afac*s3(i,j)/ave,50.d0)
+ psum=psum+s3(i,j)
+ if(s3(i,j).gt.s1) then
+ s1=s3(i,j) !Find max signal+noise power
+ i1=i !Find most reliable symbol value
+ endif
+ enddo
+ if(psum.eq.0.0) psum=1.e-6 !Guard against zero signal+noise
+
+ s2=-1.e30
+ do i=0,NQ-1
+ if(i.ne.i1 .and. s3(i,j).gt.s2) then
+ s2=s3(i,j) !Second largest signal+noise power
+ i2=i !Bin number for second largest power
+ endif
+ enddo
+ p1=s1/psum !p1, p2 are symbol metrics for ftrsd
+ p2=s2/psum
+ rxdat(j)=i1
+ rxdat2(j)=i2
+ rxprob(j)=scale*p1 !Scaled probabilities, 0 - 255
+ rxprob2(j)=scale*p2
+ enddo
+
+ return
+end subroutine sfox_prob
diff --git a/lib/superfox/sfox_remove.f90 b/lib/superfox/sfox_remove.f90 new file mode 100755 index 00000000..1bc4b978 --- /dev/null +++ b/lib/superfox/sfox_remove.f90 @@ -0,0 +1,96 @@ +subroutine sfox_remove_tone(c0,fsync)
+
+ parameter (NMAX=15*12000)
+ parameter (NFILT=8000)
+ complex c0(NMAX)
+ complex cwindow(15*12000)
+ complex cref(NMAX)
+ complex cfilt(NMAX)
+ real window(-NFILT/2:NFILT/2)
+! real endcorrection(NFILT/2+1)
+ real s(NMAX/4)
+ integer ipk(1)
+ logical first
+ data first/.true./
+ save cwindow,first,pi
+
+ if(fsync.gt.1400.0) return !Avoid a potential bounds error
+
+ if(first) then
+ pi=4.0*atan(1.0)
+ fac=1.0/float(NMAX)
+ sumw=0.0
+ do j=-NFILT/2,NFILT/2
+ window(j)=cos(pi*j/NFILT)**2
+ sumw=sumw+window(j)
+ enddo
+ cwindow=0.
+ cwindow(1:NFILT+1)=window/sumw
+ cwindow=cshift(cwindow,NFILT/2+1)
+ call four2a(cwindow,NMAX,1,-1,1)
+ cwindow=cwindow*fac ! frequency domain smoothing filter
+ first=.false.
+ endif
+
+ fsample=12000.0
+ baud=fsample/1024.0
+ df=fsample/NMAX
+ fac=1.0/NMAX
+
+ do it=1,1 ! Remove 1 tone, if present
+ cfilt=fac*c0
+ call four2a(cfilt,NMAX,1,-1,1) ! fourier transform of input data
+ iz=NMAX/4
+ do i=1,iz
+ s(i)=real(cfilt(i))**2 + aimag(cfilt(i))**2
+ enddo
+
+ ia=nint((fsync-50.0)/df)
+ ib=nint((fsync+1500.0+50.0)/df)
+ ipk=maxloc(s(ia:ib))
+ i0=ipk(1) + ia - 1
+
+ nbaud=nint(baud/df)
+ ia=i0-nbaud
+ ib=i0+nbaud
+ s0=0.0
+ s1=0.0
+ s2=0.0
+ do i=ia,ib
+ s0=s0+s(i)
+ s1=s1+(i-i0)*s(i)
+ enddo
+ delta=s1/s0
+ i0=nint(i0+delta)
+ f2=i0*df
+
+ ia=i0-nbaud
+ ib=i0+nbaud
+ do i=ia,ib
+ s2=s2 + s(i)*(i-i0)**2
+ enddo
+ sigma=sqrt(s2/s0)*df
+
+! write(*,*) 'frequency, spectral width ',f2,sigma
+ if(sigma .gt. 2.5) exit
+! write(*,*) 'remove_tone - frequency: ',f2
+
+ dt=1.0/fsample
+ do i=1, NMAX
+ arg=2*pi*f2*i*dt
+ cref(i)=cmplx(cos(arg),sin(arg))
+ enddo
+ cfilt=c0*conjg(cref) ! baseband to be filtered
+ call four2a(cfilt,NMAX,1,-1,1)
+ cfilt=cfilt*cwindow
+ call four2a(cfilt,NMAX,1,1,1)
+
+ nframe=50*3456
+ do i=1,nframe
+ cref(i)=cfilt(i)*cref(i)
+ c0(i)=c0(i)-cref(i)
+ enddo
+ enddo
+
+ return
+end subroutine sfox_remove_tone
diff --git a/lib/superfox/sfox_remove_ft8.f90 b/lib/superfox/sfox_remove_ft8.f90 new file mode 100755 index 00000000..fbfd75f0 --- /dev/null +++ b/lib/superfox/sfox_remove_ft8.f90 @@ -0,0 +1,213 @@ +subroutine sfox_remove_ft8(dd,npts)
+ use packjt77
+ include 'ft8_params.f90'
+ parameter (MAXCAND=100)
+ parameter (NP2=2812)
+ integer itone(NN)
+ integer iloc(1), ip(1)
+ integer icos7(0:6)
+ integer graymap(0:7)
+ integer*1 cw(174),apmask(174)
+ integer*1 message91(91)
+ integer*1 message77(77)
+
+ character*77 c77
+ character*37 msg37
+
+ real s8(0:7,NN)
+ real s2(0:7)
+ real ss(9)
+ real candidate(3,MAXCAND)
+ real sbase(NH1)
+ real dd(npts)
+ real bmeta(174),bmetd(174)
+ real llra(174),llrd(174)
+ complex cd0(0:3199)
+ complex csymb(32)
+ complex ctwk(32)
+ complex cs(0:7,NN)
+ data icos7/3,1,4,0,6,5,2/
+ logical first,newdat
+ logical one(0:7,0:2)
+ logical unpk77_success
+ data first/.true./
+ data graymap/0,1,3,2,5,6,4,7/
+ save one,first,twopi
+
+ if(first) then
+ one=.false.
+ do i=0,7
+ do j=0,2
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
+ first=.false.
+ twopi=8.0*atan(1.0)
+ endif
+
+ fs2=12000.0/NDOWN
+ dt2=1.0/fs2
+ nfa=500
+ nfb=2500
+ syncmin=1.5
+ nfqso=750
+ call sync8(dd,npts,nfa,nfb,syncmin,nfqso,MAXCAND,candidate,ncand,sbase)
+ newdat=.true.
+ do icand=1,ncand
+ f1=candidate(1,icand)
+ xdt=candidate(2,icand)
+ xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0))
+ call ft8_downsample(dd,newdat,f1,cd0)
+ newdat=.false.
+ i0=nint((xdt+0.5)*fs2)
+ smax=0.0
+ do idt=i0-10,i0+10
+ call sync8d(cd0,idt,ctwk,0,sync)
+ if(sync.gt.smax) then
+ smax=sync
+ ibest=idt
+ endif
+ enddo
+
+ smax=0.0
+ delfbest=0.0
+ do ifr=-5,5 !Search over +/- 2.5 Hz
+ delf=ifr*0.5
+ dphi=twopi*delf*dt2
+ phi=0.0
+ do i=1,32
+ ctwk(i)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ enddo
+ call sync8d(cd0,ibest,ctwk,1,sync)
+ if( sync .gt. smax ) then
+ smax=sync
+ delfbest=delf
+ endif
+ enddo
+
+ f1=f1+delfbest !Improved estimate of DF
+
+ call ft8_downsample(dd,newdat,f1,cd0) !Mix f1 to baseband and downsample
+
+ smax=0.0
+ do idt=-4,4 !Search over +/- one quarter symbol
+ call sync8d(cd0,ibest+idt,ctwk,0,sync)
+ ss(idt+5)=sync
+ enddo
+ smax=maxval(ss)
+ iloc=maxloc(ss)
+ ibest=iloc(1)-5+ibest
+ xdt=(ibest-1)*dt2
+ sync=smax
+
+ do k=1,NN
+ i1=ibest+(k-1)*32
+ csymb=cmplx(0.0,0.0)
+ if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31)
+ call four2a(csymb,32,1,-1,1)
+ cs(0:7,k)=csymb(1:8)/1e3
+ s8(0:7,k)=abs(csymb(1:8))
+ enddo
+
+! sync quality check
+ is1=0
+ is2=0
+ is3=0
+ do k=1,7
+ ip=maxloc(s8(:,k))
+ if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1
+ ip=maxloc(s8(:,k+36))
+ if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1
+ ip=maxloc(s8(:,k+72))
+ if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1
+ enddo
+! hard sync sum - max is 21
+ nsync=is1+is2+is3
+ if(nsync .le. 6) then ! bail out
+ nbadcrc=1
+ cycle
+ endif
+
+ nsym=1
+ nt=2**(3*nsym)
+ do ihalf=1,2
+ do k=1,29,nsym
+ if(ihalf.eq.1) ks=k+7
+ if(ihalf.eq.2) ks=k+43
+ amax=-1.0
+ do i=0,nt-1
+ i3=iand(i,7)
+ s2(i)=abs(cs(graymap(i3),ks))
+ enddo
+ i32=1+(k-1)*3+(ihalf-1)*87
+ ibmax=2
+ 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(i32+ib .gt.174) cycle
+ bmeta(i32+ib)=bm
+ den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), &
+ maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)))
+ if(den.gt.0.0) then
+ cm=bm/den
+ else ! erase it
+ cm=0.0
+ endif
+ bmetd(i32+ib)=cm
+ enddo
+ enddo
+ enddo
+
+ call normalizebmet(bmeta,174)
+ call normalizebmet(bmetd,174)
+
+ scalefac=2.83
+ llra=scalefac*bmeta
+ llrd=scalefac*bmetd
+
+ cw=0
+ dmin=0
+ norder=2
+ maxosd=-1
+ Keff=91
+ apmask=0
+ message91=0
+ cw=0
+ call decode174_91(llra,Keff,maxosd,norder,apmask,message91,cw, &
+ ntype,nharderrors,dmin)
+
+ if(nharderrors.ge.0) then
+ message77=message91(1:77)
+ else
+ cycle
+ endif
+
+ if(count(cw.eq.0).eq.174) cycle
+
+ write(c77,'(77i1)') message77
+ read(c77(72:74),'(b3)') n3
+ read(c77(75:77),'(b3)') i3
+ if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle
+ if(i3.eq.0 .and. n3.eq.2) cycle
+
+ call unpack77(c77,1,msg37,unpk77_success)
+! write(77,*) 'FT8 interference: ',msg37
+ if(.not.unpk77_success) cycle
+! Message structure: S7 D29 S7 D29 S7
+ itone(1:7)=icos7
+ itone(36+1:36+7)=icos7
+ itone(NN-6:NN)=icos7
+ k=7
+ do j=1,ND
+ i=3*j -2
+ k=k+1
+ if(j.eq.30) k=k+7
+ indx=cw(i)*4 + cw(i+1)*2 + cw(i+2)
+ itone(k)=graymap(indx)
+ enddo
+ call subtractft8(dd,itone,f1,xdt,.true.)
+! return
+ enddo
+ return
+end subroutine sfox_remove_ft8
diff --git a/lib/superfox/sfox_remove_tone.f90 b/lib/superfox/sfox_remove_tone.f90 new file mode 100755 index 00000000..f2d5a142 --- /dev/null +++ b/lib/superfox/sfox_remove_tone.f90 @@ -0,0 +1,109 @@ +subroutine sfox_remove_tone(c0,fsync)
+
+ parameter (NMAX=15*12000)
+ parameter (NFILT=8000)
+ complex c0(NMAX)
+ complex cwindow(15*12000)
+ complex cref(NMAX)
+ complex cfilt(NMAX)
+ real window(-NFILT/2:NFILT/2)
+! real endcorrection(NFILT/2+1)
+ real s(NMAX/4)
+ integer ipk(1)
+ logical first
+ data first/.true./
+ save cwindow,first,pi
+
+ if(fsync.gt.1400.0) return !Avoid a potential bounds error
+
+ if(first) then
+ pi=4.0*atan(1.0)
+ fac=1.0/float(NMAX)
+ sumw=0.0
+ do j=-NFILT/2,NFILT/2
+ window(j)=cos(pi*j/NFILT)**2
+ sumw=sumw+window(j)
+ enddo
+ cwindow=0.
+ cwindow(1:NFILT+1)=window/sumw
+ cwindow=cshift(cwindow,NFILT/2+1)
+ call four2a(cwindow,NMAX,1,-1,1)
+ cwindow=cwindow*fac ! frequency domain smoothing filter
+ first=.false.
+ endif
+
+ fsample=12000.0
+ baud=fsample/1024.0
+ df=fsample/NMAX
+ fac=1.0/NMAX
+
+ do it=1,1 ! Remove 1 tone, if present
+ cfilt=fac*c0
+ call four2a(cfilt,NMAX,1,-1,1) ! fourier transform of input data
+ iz=NMAX/4
+ do i=1,iz
+ s(i)=real(cfilt(i))**2 + aimag(cfilt(i))**2
+ enddo
+
+ ia=nint((fsync-50.0)/df)
+ ib=nint((fsync+1500.0+50.0)/df)
+
+ if (ia .lt. 1) ia=1; ! Avoid a potential bounds error
+ if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error
+
+ ipk=maxloc(s(ia:ib))
+ i0=ipk(1) + ia - 1
+
+ nbaud=nint(baud/df)
+ ia=i0-nbaud
+ ib=i0+nbaud
+
+ if (ia .lt. 1) ia=1; ! Avoid a potential bounds error
+ if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error
+
+ s0=0.0
+ s1=0.0
+ s2=0.0
+ do i=ia,ib
+ s0=s0+s(i)
+ s1=s1+(i-i0)*s(i)
+ enddo
+ delta=s1/s0
+ i0=nint(i0+delta)
+ f2=i0*df
+
+ ia=i0-nbaud
+ ib=i0+nbaud
+
+ if (ia .lt. 1) ia=1; ! Avoid a potential bounds error
+ if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error
+
+ do i=ia,ib
+ s2=s2 + s(i)*(i-i0)**2
+ enddo
+ sigma=sqrt(s2/s0)*df
+
+! write(*,*) 'frequency, spectral width ',f2,sigma
+ if(sigma .gt. 2.5) exit
+! write(*,*) 'remove_tone - frequency: ',f2
+
+ dt=1.0/fsample
+ do i=1, NMAX
+ arg=2*pi*f2*i*dt
+ cref(i)=cmplx(cos(arg),sin(arg))
+ enddo
+ cfilt=c0*conjg(cref) ! baseband to be filtered
+ call four2a(cfilt,NMAX,1,-1,1)
+ cfilt=cfilt*cwindow
+ call four2a(cfilt,NMAX,1,1,1)
+
+ nframe=50*3456
+ do i=1,nframe
+ cref(i)=cfilt(i)*cref(i)
+ c0(i)=c0(i)-cref(i)
+ enddo
+ enddo
+
+ return
+
+end subroutine sfox_remove_tone
diff --git a/lib/superfox/sfox_unpack.f90 b/lib/superfox/sfox_unpack.f90 new file mode 100755 index 00000000..24209d0a --- /dev/null +++ b/lib/superfox/sfox_unpack.f90 @@ -0,0 +1,119 @@ +subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp)
+
+ use packjt77
+ parameter (NQU1RKS=203514677)
+ integer*1 x(0:49)
+ integer*8 n58
+ logical success
+ character*336 msgbits
+ character*22 msg(10) !### only msg(1) is used ??? ###
+ character*13 foxcall,c13
+ character*10 ssignature
+ character*4 crpt(5),grid4
+ character*26 freeTextMsg
+ character*38 c
+ logical use_otp
+ data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/
+
+ ncq=0
+ if (notp.eq.0) then
+ use_otp = .FALSE.
+ else
+ use_otp = .TRUE.
+ endif
+ write(msgbits,1000) x(0:46)
+1000 format(47b7.7)
+ read(msgbits(327:329),'(b6)') i3 !Message type
+ read(msgbits(1:28),'(b28)') n28 !Standard Fox call
+ call unpack28(n28,foxcall,success)
+
+ if(i3.eq.1) then !Compound Fox callsign
+! read(msgbits(87:101),'(b15)') n15
+! call unpackgrid(n15,grid4)
+! msg(1)='CQ '//trim(foxcall)//' '//grid4
+! write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1))
+! go to 100
+ else if(i3.eq.2) then !Up to 4 Hound calls and free text
+ call unpacktext77(msgbits(161:231),freeTextMsg(1:13))
+ call unpacktext77(msgbits(232:302),freeTextMsg(14:26))
+ do i=26,1,-1
+ if(freeTextMsg(i:i).ne.'.') exit
+ freeTextMsg(i:i)=' '
+ enddo
+ write(*,1100) nutc,nsnr,dt0,nint(f0),freeTextMsg
+1100 format(i6.6,i4,f5.1,i5,1x,"~",2x,a)
+ else if(i3.eq.3) then !CQ FoxCall Grid
+ read(msgbits(1:58),'(b58)') n58 !FoxCall
+ do i=11,1,-1
+ j=mod(n58,38)+1
+ foxcall(i:i)=c(j:j)
+ n58=n58/38
+ enddo
+ foxcall(12:13)=' '
+ read(msgbits(59:73),'(b15)') n15
+ call unpackgrid(n15,grid4)
+ msg(1)='CQ '//trim(foxcall)//' '//grid4
+ write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1))
+ read(msgbits(74:105),'(b32)') n32
+ if(n32.eq.NQU1RKS) go to 100
+ call unpacktext77(msgbits(74:144),freeTextMsg(1:13))
+ call unpacktext77(msgbits(145:215),freeTextMsg(14:26))
+ do i=26,1,-1
+ if(freeTextMsg(i:i).ne.'.') exit
+ freeTextMsg(i:i)=' '
+ enddo
+ if(len(trim(freeTextMsg)).gt.0) write(*,1100) nutc,nsnr,dt0,&
+ nint(f0),freeTextMsg
+ go to 100
+ endif
+
+ j=281
+ iz=4 !Max number of reports
+ if(i3.eq.2) j=141
+ do i=1,iz !Extract the reports
+ read(msgbits(j:j+4),'(b5)') n
+ if(n.eq.31) then
+ crpt(i)='RR73'
+ else
+ write(crpt(i),1006) n-18
+1006 format(i3.2)
+ if(crpt(i)(1:1).eq.' ') crpt(i)(1:1)='+'
+ endif
+ j=j+5
+ enddo
+
+! Unpack Hound callsigns and format user-level messages:
+ iz=9 !Max number of hound calls
+ if(i3.eq.2 .or. i3.eq.3) iz=4
+ do i=1,iz
+ j=28*i + 1
+ read(msgbits(j:j+27),'(b28)') n28
+ call unpack28(n28,c13,success)
+ if(n28.eq.0 .or. n28.eq.NQU1RKS) cycle
+ msg(i)=trim(c13)//' '//trim(foxcall)
+ if(msg(i)(1:3).eq.'CQ ') then
+ ncq=ncq+1
+ else
+ if(i3.eq.2) then
+ msg(i)=trim(msg(i))//' '//crpt(i)
+ else
+ if(i.le.5) msg(i)=trim(msg(i))//' RR73'
+ if(i.gt.5) msg(i)=trim(msg(i))//' '//crpt(i-5)
+ endif
+ endif
+ if(ncq.le.1 .or. msg(i)(1:3).ne.'CQ ') then
+ write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(i))
+ endif
+ enddo
+
+ if(msgbits(306:306).eq.'1' .and. ncq.lt.1) then
+ write(*,1100) nutc,nsnr,dt0,nint(f0),'CQ '//foxcall
+ endif
+
+100 read(msgbits(307:326),'(b20)') notp
+ if (use_otp) then
+ write(ssignature,'(I6.6)') notp
+ write(*,1100) nutc,nsnr,dt0,nint(f0),'$VERIFY$ '//trim(foxcall)//' '//trim(ssignature)
+ endif
+ return
+end subroutine sfox_unpack
diff --git a/lib/superfox/sfox_wave.f90 b/lib/superfox/sfox_wave.f90 new file mode 100755 index 00000000..2e39a1c6 --- /dev/null +++ b/lib/superfox/sfox_wave.f90 @@ -0,0 +1,40 @@ +subroutine sfox_wave(fname)
+
+! Called by WSJT-X when it's time for SuperFox to transmit. Reads array
+! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory.
+
+ parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz)
+ parameter (NN=151,NSPS=1024)
+ character*(*) fname
+ integer itone(151)
+ real*8 dt,twopi,f0,baud,phi,dphi
+
+ common/foxcom/wave(NWAVE)
+
+ wave=0.
+ open(25,file=trim(fname),status='unknown',err=999)
+ read(25,'(20i4)',err=999,end=999) itone
+ close(25)
+ if(itone(1).lt.0 .or. itone(1).gt.128) go to 999
+
+! Generate the SuperFox waveform.
+
+ dt=1.d0/48000.d0
+ twopi=8.d0*atan(1.d0)
+ f0=750.0d0
+ phi=0.d0
+ baud=12000.d0/NSPS
+ k=0
+ do j=1,NN
+ f=f0 + baud*mod(itone(j),128)
+ dphi=twopi*f*dt
+ do ii=1,4*NSPS
+ k=k+1
+ phi=phi+dphi
+ xphi=phi
+ wave(k)=sin(xphi)
+ enddo
+ enddo
+
+999 return
+end subroutine sfox_wave
diff --git a/lib/superfox/sfox_wave_gfsk.f90 b/lib/superfox/sfox_wave_gfsk.f90 new file mode 100755 index 00000000..b2718723 --- /dev/null +++ b/lib/superfox/sfox_wave_gfsk.f90 @@ -0,0 +1,77 @@ +subroutine sfox_wave_gfsk()
+
+! Called by WSJT-X when it's time for SuperFox to transmit. Reads array
+! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory.
+! Generates a GFSK waveform with short ramp-up and ramp-down symbols of
+! duration NSPS/BT at the beginning and end of the waveform.
+
+ parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz)
+ parameter (NSYM=151,NSPS=1024*4)
+ parameter (NPTS=(NSYM+2)*NSPS)
+ parameter (BT=8)
+ character*40 cmsg2
+ integer itone(151)
+ real*8 dt,twopi,f0,phi,dphi_peak
+ real*8 dphi(0:NPTS-1)
+ real*8 pulse(3*NSPS)
+ logical first/.true./
+
+ common/foxcom/wave(NWAVE)
+ common/foxcom3/nslots2,cmsg2(5),itone3(151)
+ save first,twopi,dt,hmod,dphi_peak,pulse
+
+ if(first) then
+ fsample=48000.0
+ twopi=8.d0*atan(1.d0)
+ dt=1.d0/fsample
+ hmod=1.0
+ dphi_peak=twopi*hmod/real(NSPS)
+ do i=1,3*NSPS
+ tt=(i-1.5*NSPS)/real(NSPS)
+ pulse(i)=gfsk_pulse(BT,tt)
+ enddo
+ first=.false.
+ endif
+ wave=0.
+
+ itone=itone3
+ if(itone(1).lt.0 .or. itone(1).gt.128) go to 999
+
+! Generate the SuperFox waveform.
+
+ dphi=0.d0
+ do j=1,NSYM
+ ib=(j-1)*NSPS
+ ie=ib+3*NSPS-1
+ dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j)
+ enddo
+ dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS)
+ dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)=dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)+dphi_peak*itone(NSYM)*pulse(1:2*NSPS)
+
+ phi=0.d0
+ f0=750.0d0
+ dphi=dphi+twopi*f0*dt
+ k=0
+ do j=1,NSPS*(NSYM+2)-1
+ k=k+1
+ wave(k)=sin(phi)
+ phi=phi+dphi(j)
+ enddo
+
+! Add raised cosine ramps at the beginning and end of the waveform.
+! Since the modulator expects an integral number of symbols, dummy
+! symbols are added to the beginning and end of the waveform to
+! hold the ramps. All but nramp of the samples in each dummy
+! symbol will be zero.
+
+ nramp=NSPS/BT
+ wave(1:NSPS-nramp)=0.0
+ wave(NSPS-nramp+1:NSPS)=wave(NSPS-nramp+1:NSPS) * &
+ (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ k1=(NSYM+1)*NSPS+1
+ wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * &
+ (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0
+ wave(k1+nramp:NPTS)=0.0
+
+999 return
+end subroutine sfox_wave_gfsk
diff --git a/lib/superfox/sfoxsim.f90 b/lib/superfox/sfoxsim.f90 new file mode 100755 index 00000000..8dac07a8 --- /dev/null +++ b/lib/superfox/sfoxsim.f90 @@ -0,0 +1,164 @@ +program sfoxsim
+
+! - Generate complex-valued SuperFox waveform, cdat.
+! - Pass cdat through Watterson channel simulator
+! - Add noise to the imaginary part of cdat and write to wav file.
+
+ use wavhdr
+ use qpc_mod
+ use sfox_mod
+
+ type(hdr) h !Header for .wav file
+ logical*1 bMoreCQs !Include a CQ when space available?
+ logical*1 bSendMsg !Send a Free text message
+ integer*2 iwave(NMAX) !Generated i*2 waveform
+ integer isync(24) !Indices of sync symbols
+ integer itone(151) !Symbol values, data and sync
+ integer*1 xin(0:49)
+ integer*1 y(0:127)
+ real*4 xnoise(NMAX) !Random noise
+ real*4 dat(NMAX) !Generated real data
+ complex cdat(NMAX) !Generated complex waveform
+ complex crcvd(NMAX) !Signal as received
+ real, allocatable :: s3(:,:) !Symbol spectra: will be s3(NQ,NN)
+ integer, allocatable :: msg0(:) !Information symbols
+ integer, allocatable :: chansym(:) !Encoded data, 7-bit integers
+ character fname*17,arg*12,channel*2,foxcall*11
+ character*10 ckey
+ character*26 text_msg
+ character*120 line !SuperFox message pieces
+ character*40 cmsg(5)
+ data ckey/'0000000000'/
+ data cmsg/'W0AAA RR73; W5FFF <K1JT> -18', &
+ 'W1BBB RR73; W6GGG <K1JT> -15', &
+ 'W2CCC RR73; W7HHH <K1JT> -12', &
+ 'W3DDD RR73; W8III <K1JT> -09', &
+ 'W4EEE RR73; W9JJJ <K1JT> -06'/
+ data text_msg/'0123456789ABCDEFGHIJKLMNOP'/
+ data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, &
+ 83,84,86,89/
+
+ nargs=iargc()
+ if(nargs.ne.10) then
+ print*,'Usage: sfoxsim f0 DT Chan FoxC H1 H2 CQ FT nfiles snr'
+ print*,'Example: sfoxsim 750 0.0 MM K1JT 5 1 0 0 10 -15'
+ print*,' f0=0 to dither f0 and DT'
+ print*,' Chan Channel type AW LQ LM LD MQ MM MD HQ HM HD'
+ print*,' FoxC Fox callsign'
+ print*,' key'
+ print*,' H1 number of Hound calls with RR73'
+ print*,' H2 number of Hound calls with reports'
+ print*,' CQ=1 to include a CQ message'
+ print*,' FT=1 to include a Free Text message'
+ go to 999
+ endif
+ call getarg(1,arg)
+ read(arg,*) f0
+ call getarg(2,arg)
+ read(arg,*) xdt
+ call getarg(3,channel)
+ call getarg(4,foxcall)
+ call getarg(5,arg)
+ read(arg,*) nh1
+ call getarg(6,arg)
+ read(arg,*) nh2
+ call getarg(7,arg)
+ read(arg,*) ncq
+ bMoreCQs=ncq.ne.0
+ call getarg(8,arg)
+ read(arg,*) nft
+ bSendMsg=nft.ne.0
+ call getarg(9,arg)
+ read(arg,*) nfiles
+ call getarg(10,arg)
+ read(arg,*) snr
+
+ fspread=0.0
+ delay=0.0
+ fsample=12000.0 !Sample rate (Hz)
+ call sfox_init(7,127,50,channel,fspread,delay,fsample,24)
+ txt=(NN+NS)*NSPS/fsample
+ write(*,1000) f0,xdt,channel,snr
+1000 format('sfoxsim: f0= ',f5.1,' dt= ',f4.2,' Channel: ',a2,' snr: ',f5.1,' dB')
+
+! Allocate storage for arrays that depend on code parameters.
+ allocate(s3(0:NQ-1,0:NN-1))
+ allocate(msg0(1:KK))
+ allocate(chansym(0:NN-1))
+
+ if(nft.ne.0) then
+ open(10,file='text_msg.txt',status='old',err=2)
+ read(10,*) text_msg
+ endif
+
+2 idum=-1
+ rms=100.
+ baud=fsample/nsps !Keying rate, 11.719 baud for nsps=1024
+ bandwidth_ratio=2500.0/fsample
+ do i=1,5
+ cmsg(i)=cmsg(i)(1:19)//trim(foxcall)//cmsg(i)(24:28)
+ if(i.gt.nh1 .and. i.gt.nh2) then
+ cmsg(i)=''
+ elseif(i.gt.nh1) then
+ cmsg(i)=cmsg(i)(13:18)//trim(foxcall)//cmsg(i)(25:28)
+ elseif(i.gt.nh2) then
+ cmsg(i)=cmsg(i)(1:6)//trim(foxcall)//' RR73'
+ endif
+! write(*,*) 'Debug ',cmsg(i)
+ enddo
+
+ if((nh1+nh2).eq.0 .and. bMoreCQs) cmsg(1)='CQ '//trim(foxcall)//' FN20'
+
+! Generate a SuperFox message
+ nslots=5
+ call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages
+ call sfox_pack(line,ckey,bMoreCQs,bSendMsg,text_msg,xin)
+ call qpc_encode(y,xin)
+
+ y=cshift(y,1)
+ y(127)=0
+ chansym=y(0:126)
+
+ sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snr)
+ sigr=sqrt(2.)*sig
+ if(snr.gt.90.0) sig=1.0
+
+ do ifile=1,nfiles
+ xnoise=0.
+ if(snr.lt.90) then
+ do i=1,NMAX
+ xnoise(i)=gran() !Gaussian noise
+ enddo
+ endif
+
+ f1=f0
+ if(f0.eq.0.0) then
+ f1=750 + 20.0*(ran1(idum)-0.5)
+ xdt=ran1(idum)-0.5
+ endif
+! Generate cdat, the SuperFox waveform
+ call sfox_gen_gfsk(chansym,f1,isync,itone,cdat)
+
+ crcvd=0.
+ crcvd(1:NMAX)=cshift(cdat(1:NMAX),-nint((0.5+xdt)*fsample))
+ if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample,&
+ delay,fspread)
+
+ dat=aimag(sigr*crcvd(1:NMAX)) + xnoise !Add generated AWGN noise
+ fac=32767.0
+ if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX))
+ if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX))
+
+ h=default_header(12000,NMAX)
+ fname='000000_000001.wav'
+ nsec=(ifile-1)*30
+ nhr=nsec/3600
+ nmin=(nsec-nhr*3600)/60
+ nsec=mod(nsec,60)
+ write(fname(8:13),'(3i2.2)') nhr,nmin,nsec
+ open(10,file=trim(fname),access='stream',status='unknown')
+ write(10) h,iwave(1:NMAX) !Save the .wav file
+ close(10)
+ enddo ! ifile
+
+999 end program sfoxsim
diff --git a/lib/superfox/sfrx.f90 b/lib/superfox/sfrx.f90 new file mode 100755 index 00000000..51c71f93 --- /dev/null +++ b/lib/superfox/sfrx.f90 @@ -0,0 +1,59 @@ +program sfrx
+
+! Command-line SuperFox decoder
+
+ use sfox_mod
+ use julian
+
+ integer*2 iwave(NMAX)
+ integer ihdr(11)
+ character*120 fname
+ include 'gtag.f90'
+
+ narg=iargc()
+
+ if(narg.lt.1) then
+ print*,'Usage: sfrx fsync ftol infile [...]'
+ print*,' sfrx 775 10 240811_102400.wav'
+ print*,'Reads one or more .wav files and calls SuperFox decoder on each.'
+ print '(" Git tag: ",z9)',ntag
+ go to 999
+ endif
+
+ call getarg(1,fname)
+ read(fname,*,err=1) fsync
+ call getarg(2,fname)
+ read(fname,*,err=1) ftol
+
+ nfqso=nint(fsync)
+ ntol=nint(ftol)
+
+1 nf=0
+ nd=0
+ nv=0
+
+ do ifile=3,narg
+ call getarg(ifile,fname)
+ write(72,*) ifile,narg,fname
+ open(10,file=trim(fname),status='old',access='stream',err=4)
+
+ go to 5
+4 print*,'Cannot open file ',trim(fname)
+ go to 999
+5 read(10) ihdr,iwave
+ close(10)
+
+ nz=len(trim(fname))
+ nyymmdd=ihdr(1)
+ nutc=ihdr(2)
+ if(fname(nz-3:nz).eq.'.wav') then
+ read(fname(nz-16:nz-11),*) nyymmdd
+ read(fname(nz-9:nz-4),*) nutc
+ endif
+
+ call sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave)
+
+ nf=nf+1
+ enddo
+
+999 end program sfrx
diff --git a/lib/superfox/sfrx_sub.f90 b/lib/superfox/sfrx_sub.f90 new file mode 100755 index 00000000..1168610a --- /dev/null +++ b/lib/superfox/sfrx_sub.f90 @@ -0,0 +1,54 @@ +subroutine sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave)
+
+ use sfox_mod
+ use julian
+
+ integer*2 iwave(NMAX)
+ integer*8 secday,ntime8
+ integer*1 xdec(0:49)
+ character*13 foxcall
+ complex c0(NMAX) !Complex form of signal as received
+ real dd(NMAX)
+ logical crc_ok
+ data secday/86400/
+
+ fsync=nfqso
+ ftol=ntol
+ fsample=12000.0
+ call sfox_init(7,127,50,'no',fspread,delay,fsample,24)
+ npts=15*12000
+
+ if(nyymmdd.eq.-1) then
+ ntime8=itime8()/30
+ ntime8=30*ntime8
+ else
+ iyr=2000+nyymmdd/10000
+ imo=mod(nyymmdd/100,100)
+ iday=mod(nyymmdd,100)
+ ih=nutc/10000
+ im=mod(nutc/100,100)
+ is=mod(nutc,100)
+ ntime8=secday*(JD(iyr,imo,iday)-2440588) + 3600*ih + 60*im + is
+ endif
+
+ dd=iwave
+ call sfox_remove_ft8(dd,npts)
+
+ call sfox_ana(dd,npts,c0,npts)
+
+ call sfox_remove_tone(c0,fsync) ! Needs testing
+
+ ndepth=3
+ dth=0.5
+ damp=1.0
+
+ call qpc_decode2(c0,fsync,ftol, xdec,ndepth,dth,damp,crc_ok, &
+ snrsync,fbest,tbest,snr)
+ if(crc_ok) then
+ nsnr=nint(snr)
+ nsignature = 1
+ call sfox_unpack(nutc,xdec,nsnr,fbest-750.0,tbest,foxcall,nsignature)
+ endif
+
+ return
+end subroutine sfrx_sub
diff --git a/lib/superfox/sftx.f90 b/lib/superfox/sftx.f90 new file mode 100755 index 00000000..d2ca7792 --- /dev/null +++ b/lib/superfox/sftx.f90 @@ -0,0 +1,107 @@ +program sftx
+
+! This program is required in order to create a SuperFox transmission.
+
+! The present version goes through the following steps:
+! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X
+! writable data directory.
+! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound
+! calls, and the report or RR73 to be sent to each Hound.
+! 3. Assemble and encode a single SuperFox message to produce itone(1:151),
+! the array of channel symbol values.
+! 4. Write the contents of array itone to file 'sfox_2.dat'.
+
+ use qpc_mod
+ use sfox_mod
+ character*120 fname !Corrected path for sfox_1.dat
+ character*120 line !List of SuperFox message pieces
+ character*40 cmsg(5) !Old-style Fox messages
+ character*26 freeTextMsg
+ character*2 arg
+ character*10 ckey
+! character*9 foxkey
+ character*11 foxcall0,foxcall
+ logical*1 bMoreCQs,bSendMsg
+ logical crc_ok
+ real py(0:127,0:127) !Probabilities for received synbol values
+ integer*8 n47
+ integer itone(151) !SuperFox channel-symbol values
+ integer*1 xin(0:49) !Packed message as 7-bit symbols
+ integer*1 xdec(0:49) !Decoded message
+ integer*1 y(0:127) !Encoded symbols as i*1 integers
+ integer*1 ydec(0:127) !Decoded codeword
+ integer*1 yy(0:10)
+ integer chansym0(127) !Transmitted symbols, data only
+ integer chansym(127) !Received symbols, data only
+ integer isync(24) !Symbol numbers for sync tones
+ data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, &
+ 83,84,86,89/
+ include 'gtag.f90'
+
+ narg=iargc()
+ if(narg.ne.3) then
+ print '(" Git tag: ",z9)',ntag
+ go to 999
+ endif
+
+! sftx <message_file_name> <foxcall> <ckey>
+ call getarg(1,fname)
+ do i=1,len(trim(fname))
+ if(fname(i:i).eq.'\\') fname(i:i)='/'
+ enddo
+ call getarg(2,foxcall0)
+ call getarg(3,ckey)
+
+! if((foxkey(foxcall0).ne.ckey).and.(INDEX(ckey,'OTP:').eq.0)) then ! neither kind
+! itone=-99
+! go to 100
+! endif
+
+ fsample=12000.0
+ call sfox_init(7,127,50,'no',fspread,delay,fsample,24)
+ open(25,file=trim(fname),status='unknown')
+ do i=1,5
+ read(25,1000,end=10) cmsg(i)
+1000 format(a40)
+ enddo
+ i=6
+10 close(25)
+ nslots=i-1
+ freeTextMsg=' '
+ bMoreCQs=cmsg(1)(40:40).eq.'1'
+ bSendMsg=cmsg(nslots)(39:39).eq.'1'
+ if(bSendMsg) then
+ freeTextMsg=cmsg(nslots)(1:26)
+ if(nslots.gt.2) nslots=2
+ endif
+
+ call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages
+
+! Pack message information and CRC into xin(0:49)
+ call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin)
+ call qpc_encode(y,xin) !Encode the message to 128 symbols
+ y=cshift(y,1) !Puncture the code by removing y(0)
+ y(127)=0
+ chansym0=y(0:126)
+
+! Create the full itone sequence containing both data and sync symbols
+ j=1
+ k=0
+ do i=1,NDS
+ if(j.le.NS .and. i.eq.isync(j)) then
+ if(j.lt.NS) j=j+1 !Index for next sync symbol
+ itone(i)=0 !Insert sync symbol at tone 0
+ else
+ k=k+1
+ itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc.
+ endif
+ enddo
+
+100 i1=max(index(fname,'sfox_1'),1)
+ fname(i1:i1+9)='sfox_2.dat'
+ open(25,file=trim(fname),status='unknown')
+ write(25,1100) itone
+1100 format(20i4)
+ close(25)
+
+999 end program sftx
diff --git a/lib/superfox/sftx_sub.f90 b/lib/superfox/sftx_sub.f90 new file mode 100755 index 00000000..138b4855 --- /dev/null +++ b/lib/superfox/sftx_sub.f90 @@ -0,0 +1,65 @@ +subroutine sftx_sub(ckey0)
+
+! This routine is required in order to create a SuperFox transmission.
+
+! The present version goes through the following steps:
+! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X
+! writable data directory.
+! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound
+! calls, and the report or RR73 to be sent to each Hound.
+! 3. Assemble and encode a single SuperFox message to produce itone(1:151),
+! the array of channel symbol values.
+! 4. Write the contents of array itone to file 'sfox_2.dat'.
+
+ use qpc_mod
+ use sfox_mod
+ character*120 line !List of SuperFox message pieces
+ character*40 cmsg !Old-style Fox messages
+ character*26 freeTextMsg
+ character*(*) ckey0
+ character*10 ckey
+ character*11 foxcall
+ logical*1 bMoreCQs,bSendMsg
+ integer*1 xin(0:49) !Packed message as 7-bit symbols
+ integer*1 y(0:127) !Encoded symbols as i*1 integers
+ integer chansym0(127) !Transmitted symbols, data only
+ integer isync(24) !Symbol numbers for sync tones
+ common/foxcom3/nslots,cmsg(5),itone(151)
+ data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, &
+ 83,84,86,89/
+
+ ckey=ckey0
+
+ fsample=12000.0
+ call sfox_init(7,127,50,'no',fspread,delay,fsample,24)
+ freeTextMsg=' '
+ bMoreCQs=cmsg(1)(40:40).eq.'1'
+ bSendMsg=cmsg(nslots)(39:39).eq.'1'
+ if(bSendMsg) then
+ freeTextMsg=cmsg(nslots)(1:26)
+ if(nslots.gt.4) nslots=4
+ endif
+
+ call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages
+
+! Pack message information and CRC into xin(0:49)
+ call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin)
+ call qpc_encode(y,xin) !Encode the message to 128 symbols
+ y=cshift(y,1) !Puncture the code by removing y(0)
+ y(127)=0
+ chansym0=y(0:126)
+
+! Create the full itone sequence containing both data and sync symbols
+ j=1
+ k=0
+ do i=1,NDS
+ if(j.le.NS .and. i.eq.isync(j)) then
+ if(j.lt.NS) j=j+1 !Index for next sync symbol
+ itone(i)=0 !Insert sync symbol at tone 0
+ else
+ k=k+1
+ itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc.
+ endif
+ enddo
+
+end subroutine sftx_sub
diff --git a/lib/superfox/superfox_qpc_2.txt b/lib/superfox/superfox_qpc_2.txt new file mode 100755 index 00000000..98c0da79 --- /dev/null +++ b/lib/superfox/superfox_qpc_2.txt @@ -0,0 +1,66 @@ + Bit packing of SuperFox QPC Messages
+-----------------------------------------------------------------------------
+The IV3NWV Q-ary Polar Code has parameters (n,k) = (127,50). The last
+three 7-bit information symbols convey a 21-bit CRC based on the first
+47 symbols. Thus, each Super Fox transmission carries a payload of
+47*7=329 bits. On a modern x86 processor the decoder executes in
+deterministic time around 5 ms per decode, and always produces a
+result. The CRC test rejects all but around 1 in two million false
+decodes.
+
+Bit fields are labeled with tags as defined in the QEX article "The
+FT4 and FT8 Communication Protocols" by Franke, Somerville, and Taylor
+in QEX for July/August 2020, available on the WSJT web site here:
+https://wsjt.sourceforge.io/FT4_FT8_QEX.pdf. As one example, the tag
+'c28' denotes a standard callsign, which requires 28 bits.
+
+=============================================================================
+i3 = 0: Standard message: FoxCall, up to 9 HoundCalls, up to 4 signal
+reports, "MoreCQs" flag, a digital signature, and a 3-bit message type.
+-----------------------------------------------------------------------------
+ F H1 H2 H3 H4 H5 H6 H7 H8 H9 R6 R7 R8 R9 U Q D M Type
+c28 c28 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u5 q1 d20 i3=0 Std Msg
+ 280 300 305 326 329
+=============================================================================
+i3 = 1: If Fox uses a compound callsign we have space for only 8 Hound calls.
+Otherwise like type i3=0.
+-----------------------------------------------------------------------------
+ FC H1 H2 H2 H4 H5 H6 H7 H8 R5 R6 R7 R8 U Q D M
+c58 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u3 q1 d20 i3=1
+ 58 282 302 305 326 329
+=============================================================================
+i3 = 2: A free text message with up to 26 characters can be transmitted along
+with messages to as many as 4 Hounds conveying either reports or RR73s.
+-----------------------------------------------------------------------------
+ F H1 H2 H3 H4 R1 R2 R3 R4 T T U Q D M Type
+c28 c28 c28 c28 c28 r5 r5 r5 r5 t71 t71 u3 q1 d20 i3=2 FT+4H
+ 140 160 302 305 326 329
+=============================================================================
+i3 = 3: Message "CQ FoxCall Grid <Free text>"
+-----------------------------------------------------------------------------
+ FC G T T U Q D M Type
+c58 g15 t71 t71 u90 q1 d20 i3=3 CQ FT
+ 58 73 144 215 305 326 329
+=============================================================================
+
+D Digital signature (20 bits)
+F Fox call (28 bits)
+FC Compound Fox call (58 bits)
+G Grid locator (15 bits)
+H Hound call (28 bits)
+M Message type (3 bits)
+Q MoreCQs flag
+R Report, (5 bits: -18 to +12 dB, or RR73)
+T Free text, up to 26 characters total
+U Unused bits
+
+Unused callsign slots are set to the numerical value for "QU1RKS", and
+ignored when received. Similarly for unused t71 slots. Unused report
+slots are set to 0 (-20 dB). "CQ FoxCall" will be displayed along
+with other messages if the "q1" bit is 1.
+
+The SuperFox decoder displays its results with a separate line for each Hound.
+Thus, the old-style message "K1ABC RR73; W9XYZ <VP8PJ> -14" becomes
+
+K1ABC VP8PJ RR73
+W9XYZ VP8PJ -14
diff --git a/lib/superfox/twkfreq2.f90 b/lib/superfox/twkfreq2.f90 new file mode 100755 index 00000000..443088c6 --- /dev/null +++ b/lib/superfox/twkfreq2.f90 @@ -0,0 +1,19 @@ +subroutine twkfreq2(c3,c4,npts,fsample,fshift)
+
+! Adjust frequency of complex waveform
+
+ complex c3(npts)
+ complex c4(npts)
+ complex w,wstep
+ data twopi/6.283185307/
+
+ w=1.0
+ dphi=fshift*twopi/fsample
+ wstep=cmplx(cos(dphi),sin(dphi))
+ do i=1,npts
+ w=w*wstep
+ c4(i)=w*c3(i)
+ enddo
+
+ return
+end subroutine twkfreq2
diff --git a/lib/sync4.f90 b/lib/sync4.f90 index 00387fdb..d8a130d2 100755 --- a/lib/sync4.f90 +++ b/lib/sync4.f90 @@ -85,7 +85,7 @@ subroutine sync4(dat,jz,ntol,nfqso,mode,mode4,minwidth,dtx,dfx,snrx, & enddo
if(syncbest.lt.-1.e29) go to 900
ccfred=red
- call pctile(ccfred(ia:ib),ib-ia+1,45,base)
+ call pctile(ccfred(iaa:ibb),ibb-iaa+1,45,base)
ccfred=ccfred-base
dfx=ipk*df
diff --git a/lib/testEchoCall.f90 b/lib/testEchoCall.f90 new file mode 100755 index 00000000..71f40bff --- /dev/null +++ b/lib/testEchoCall.f90 @@ -0,0 +1,48 @@ +program testEchoCall
+
+ parameter (NSPS=4096,NH=NSPS/2,NZ=3*12000)
+ integer*2 iwave(NZ) !Raw data, 12000 Hz sample rate
+ integer ihdr(11)
+ integer*1 itone(6)
+ character*120 fname
+ character*6 rxcall,hhmmss
+ common/echocom/nclearave,nsum,blue(4096),red(4096)
+ common/echocom2/fspread_self,fspread_dx
+
+ narg=iargc()
+ if(narg.lt.1) then
+ print*,'Usage: testEchoCall fname1 [fname2, ...]'
+ go to 999
+ endif
+
+ write(*,1000)
+1000 format(' UTC Hour Level Doppler Width N Q DF' &
+ ' SNR dBerr Message'/82('-'))
+
+ nclearave=1
+ navg=10
+ nauto=1
+ nqual=0
+ do ifile=1,narg
+ call getarg(ifile,fname)
+ open(10,file=trim(fname),access='stream',status='unknown')
+ read(10) ihdr,iwave
+ close(10)
+
+! Retrieve params known at time of transmissiion and saved in iwave
+ call save_echo_params(nDop,nDopAudio,nfrit,f1,fspread,ndf,itone,iwave,-1)
+ fspread_self=fspread
+
+ call avecho(iwave,0,nfrit,ndf,nauto,navg,nqual,f1,xlevel,snrdb,db_err,dfreq, &
+ width,bDiskData,bEchoCall,txcall,rxcall)
+ i1=index(fname,'.wav')
+ hhmmss=fname(i1-6:i1-1)
+ read(hhmmss,'(3i2)') ih,im,is
+ hour=ih + im/60.0 + is/3600.0
+ write(*,1110) hhmmss,hour,xlevel,ndop,fspread,nsum,nqual,nint(dfreq), &
+ snrdb,db_err,rxcall
+1110 format(a6,2x,f7.4,2x,f5.2,1x,i7,1x,f7.1,1x,i5,1x,i5,1x,i6,1x,f6.1,1x,f7.1,3x,a6)
+ nclearave=0
+ enddo
+
+999 end program testEchoCall
diff --git a/lib/test_qra64.f90 b/lib/test_qra64.f90 deleted file mode 100755 index eb6543cb..00000000 --- a/lib/test_qra64.f90 +++ /dev/null @@ -1,129 +0,0 @@ -program test_qra64
-
- character*71 cmd1,cmd2,line
- character*22 msg
- character*8 arg
- character*1 csubmode
- integer nretcode(0:11)
- logical decok
-
- nargs=iargc()
- if(nargs.ne.9) then
- print*,'Usage: test_qra64 "msg" A-D depth freq DT fDop TRp nfiles SNR'
- print*,'Example: test_qra64 "K1ABC W9XYZ EN37" A 3 1000 0.0 5.0 60 100 -20'
- print*,' SNR = 0 to loop over all relevant SNRs'
- go to 999
- endif
- call getarg(1,msg)
- call getarg(2,csubmode)
- call getarg(3,arg)
- read(arg,*) ndepth
- call getarg(4,arg)
- read(arg,*) nf0
- call getarg(5,arg)
- read(arg,*) dt
- call getarg(6,arg)
- read(arg,*) fDop
- call getarg(7,arg)
- read(arg,*) ntrperiod
- call getarg(8,arg)
- read(arg,*) nfiles
- call getarg(9,arg)
- read(arg,*) nsnr
-
- nsps=6192
- i50=-28
- ia=-20
- ib=-33
- if(nsnr.ne.0) then
- ia=nsnr
- ib=nsnr
- endif
-
- baud=12000.0/nsps
- tsym=1.0/baud
-
-! 1 2 3 4 5 6 7
-! 12345678901234567890123456789012345678901234567890123456789012345678901'
- cmd1='qra64sim "K1ABC W9XYZ EN37 " A 1 0.2 0.00 100 F -20 > junk0'
-
- cmd2='jt9 -q -L 300 -H 3000 -f 1000 -d 3 -b A *.wav > junk'
-
- write(cmd1(10:33),'(a)') '"'//msg//'"'
- cmd1(35:35)=csubmode
- write(cmd1(40:43),'(f4.1)') fDop
- write(cmd1(44:48),'(f5.2)') dt
- write(cmd1(49:53),'(i5)') nfiles
-
- write(cmd2(26:29),'(i4)') nf0
- write(cmd2(34:34),'(i1)') ndepth
- cmd2(39:39)=csubmode
-
- call system('rm -f *.wav')
-
- write(*,1000) (j,j=0,11)
- write(12,1000) (j,j=0,11)
-1000 format(/'SNR d Dop Sync Dec Bad',i6,11i4,' tdec'/80('-'))
-
- dterr=tsym/4.0
- nferr=max(1,nint(0.5*baud),nint(fdop/3.0))
- ndecodes0=nfiles
-
- do nsnr=ia,ib,-1
- nsync=0
- ndecodes=0
- nfalse=0
- nretcode=0
- write(cmd1(57:59),'(i3)') nsnr
- call system(cmd1)
- call sec0(0,tdec)
- call system(cmd2)
- call sec0(1,tdec)
- open(10,file='junk',status='unknown')
- n=0
- do iline=1,9999
- read(10,'(a71)',end=10) line
- if(index(line,'<Decode').eq.1) cycle
- read(line(11:20),*) xdt,nf
- irc=-1
- if(line(23:23).ne.' ') read(line(45:46),*) irc
- decok=index(line,'W9XYZ').gt.0
- if((abs(xdt-dt).le.dterr .and. abs(nf-nf0).le.nferr) .or. decok) then
- nsync=nsync+1
- endif
- if(irc.lt.0) cycle
- if(decok) then
- i=irc
- if(i.le.11) then
- ndecodes=ndecodes + 1
- else
- i=mod(i,10)
- endif
- nretcode(i)=nretcode(i) + 1
- else
- nfalse=nfalse + 1
- print*,'False: ',line
- endif
- enddo ! iline
-10 close(10)
- write(*,1100) nsnr,ndepth,fDop,nsync,ndecodes,nfalse,nretcode, &
- tdec/nfiles
- write(12,1100) nsnr,ndepth,fDop,nsync,ndecodes,nfalse,nretcode, &
- tdec/nfiles
-1100 format(i3,i2,f5.1,2i5,i4,i6,11i4,f6.2)
- if(ndecodes.lt.nfiles/2 .and. ndecodes0.ge.nfiles/2) then
- snr_thresh=nsnr + float(nfiles/2 - ndecodes)/(ndecodes0-ndecodes)
- write(13,1200) ndepth,fdop,csubmode,snr_thresh
-1200 format(i1,f6.1,2x,a1,f7.1)
- flush(13)
- endif
- flush(6)
- flush(12)
- if(ndecodes.eq.0) exit !Bail out if no decodes at this SNR
- ndecodes0=ndecodes
- enddo ! nsnr
-
-999 end program test_qra64
-
- include 'sec0.f90'
-
diff --git a/lib/types.f90 b/lib/types.f90 index 88fb1cfe..456938b4 100755 --- a/lib/types.f90 +++ b/lib/types.f90 @@ -7,4 +7,12 @@ module types integer, parameter :: dp = REAL64
integer, parameter :: qp = REAL128
+ type q3list
+ character*6 call
+ character*4 grid
+ integer nsec
+ integer nfreq
+ integer moonel
+ end type q3list
+
end module types
diff --git a/lib/wsprd/wsprd.c b/lib/wsprd/wsprd.c index e0109da8..d269df64 100755 --- a/lib/wsprd/wsprd.c +++ b/lib/wsprd/wsprd.c @@ -35,6 +35,7 @@ #include <stdint.h>
#include <time.h>
#include <fftw3.h>
+#include <errno.h>
#include "fano.h"
#include "jelinek.h"
@@ -77,7 +78,7 @@ unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, fp = fopen(ptr_to_infile,"rb");
if (fp == NULL) {
- fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile);
+ fprintf(stderr, "Cannot open data file '%s': %s\n", ptr_to_infile, strerror(errno));
return 1;
}
nr=fread(c2file,sizeof(char),14,fp);
@@ -146,6 +147,7 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *q nr=fread(buf2,2,npoints,fp); //Read raw data
fclose(fp);
if( nr == 0 ) {
+ free(buf2);
fprintf(stderr, "No data in file '%s'\n", ptr_to_infile);
return 1;
}
@@ -1165,7 +1167,7 @@ int main(int argc, char *argv[]) for (k=0; k<162; k++) { //Sum over symbols
ifd=ifr+((float)k-81.0)/81.0*( (float)idrift )/(2.0*df);
kindex=k0+2*k;
- if( kindex < nffts ) {
+ if( kindex >= 0 && kindex < nffts ) {
p0=ps[ifd-3][kindex];
p1=ps[ifd-1][kindex];
p2=ps[ifd+1][kindex];
|
